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;
  }
Ejemplo n.º 2
0
 /**
  * Retrieves from default AudioFileIO all supported extensions and builds a regular expression
  * matching all file whose name ends with one of those extensions
  */
 private void loadSupportedExtension() {
   Iterator<String> it = AudioFileIO.getDefaultAudioFileIO().getSupportedExtensions();
   String extension;
   final StringBuilder regExp = new StringBuilder(".*\\.(");
   while (it.hasNext()) {
     extension = (String) it.next();
     regExp.append(extension).append("|");
   }
   regExp.append(")");
   regExpMatchingSupportedExtension = Pattern.compile(regExp.toString());
 }
 public boolean save() {
   boolean success = false;
   try {
     if (audiofile != null) {
       AudioFileIO.write(audiofile);
       success = true;
     }
   } catch (Exception e) {
     log.error("save(): error saving tag, filename=" + filename, e);
   }
   return success;
 }
 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);
   }
 }