示例#1
0
  @Override
  public void parse(Builder b) throws IOException {

    Logger.getLogger("org.jaudiotagger").setLevel(Level.OFF);

    try {
      audio = AudioFileIO.read(new File(src.path()));
    } catch (CannotReadException e) {
      System.out.println(
          "Detected empty or corrupt Music file '" + src.path() + "': " + e.getMessage());
    } catch (TagException e) {
      System.out.println(
          "Detected empty or corrupt Music file '" + src.path() + "': " + e.getMessage());
    } catch (ReadOnlyFileException e) {
      System.out.println(
          "Detected empty or corrupt Music file '" + src.path() + "': " + e.getMessage());
    } catch (InvalidAudioFrameException e) {
      System.out.println(
          "Detected empty or corrupt Music file '" + src.path() + "': " + e.getMessage());
    }
    try {
      builder = b;
      atts.add(NAME, token("." + src.name() + ".deepfs"));
      atts.add(TYPE, META);
      builder.startElem(FOLDER, atts);
      insertMusicMetadata();
      builder.endElem();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  public String getSongTitle(String songFilePath) {

    String songTitle = "Title";

    // Try to get the song title from the ID3 tag.
    File songFile = new File(songFilePath);
    AudioFile audioFile = null;
    Tag tag = null;
    try {
      audioFile = AudioFileIO.read(songFile);
    } catch (CannotReadException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (TagException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ReadOnlyFileException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InvalidAudioFrameException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    tag = audioFile.getTag();
    songTitle = tag.getFirst(FieldKey.TITLE);

    // If the ID3 tag doesn't give us the info we need, just use the file name.
    if (songTitle.equals("Title") || songTitle.isEmpty()) {
      int indexOfLastSlash = songTitle.lastIndexOf("/") + 1;
      int indexOfLastDot = songTitle.lastIndexOf(".");
      songTitle = songTitle.substring(indexOfLastSlash, indexOfLastDot);
    }

    return songTitle;
  }