Ejemplo n.º 1
0
  public Tag getTag(File file) {
    Tag result = new Tag();
    AudioFile audiofile;
    try {
      audiofile = AudioFileIO.read(file);

      entagged.audioformats.Tag entaggedtag = audiofile.getTag();
      result.setAlbum(entaggedtag.getFirstAlbum());
      result.setArtist(entaggedtag.getFirstArtist());
      result.setTitle(entaggedtag.getFirstTitle());
      result.setYear(entaggedtag.getFirstYear());
      result.setSamplerate(audiofile.getSamplingRate());
      result.setBitrate(audiofile.getBitrate());

      try {
        result.setTracknumber(Integer.parseInt(entaggedtag.getFirstTrack()));
      } catch (NumberFormatException e) {
        System.out.println("No Tracknumber for file " + file.toString());
      }
      result.setTime((long) (audiofile.getPreciseLength() * 1000));
    } catch (CannotReadException e) {
      System.out.println("Exception for file:" + file.toString() + " " + e.toString());
    } catch (Exception e) {
      System.out.println("Exception for file:" + file.toString() + " " + e.toString());
    } finally {
      result.fillBlanks(file);
    }

    // TODO Auto-generated method stub
    return result;
  }
 public EntaggedTagWriter(String filename, int mode) {
   try {
     this.filename = filename;
     if (log.isDebugEnabled()) log.debug("EntaggedTagWriter(): filename=" + filename);
     audiofile = AudioFileIO.read(new File(filename));
     if (audiofile != null) {
       tag = audiofile.getTag();
       if (log.isDebugEnabled()) log.debug("EntaggedTagWriter(): tag=" + tag);
     }
     int file_type = AudioUtil.getAudioFileType(filename);
     if ((file_type == AUDIO_FILE_TYPE_FLAC) || (file_type == AUDIO_FILE_TYPE_OGG)) {
       write_extended_info = true;
     }
   } catch (Exception e) {
     log.error("EntaggedTagWriter(): error Exception", e);
   }
 }