Package org.jaudiotagger.tag

Examples of org.jaudiotagger.tag.Tag


    public MusicFile(String filename) {
        AudioFile audioFile;
        try {
          audioFile = AudioFileIO.read(new File(filename));
       
            Tag tag = audioFile.getTag();
            if (tag != null) {
                album = tag.getFirst(FieldKey.ALBUM);
                artist = tag.getFirst(FieldKey.ARTIST);
                genre = getGenre(tag.getFirst(FieldKey.GENRE));
                year = tag.getFirst(FieldKey.YEAR);
                title = tag.getFirst(FieldKey.TITLE);
               
                for (Artwork aw : tag.getArtworkList())
                    image = new DcImageIcon(aw.getBinaryData());
               
                bitrate = (int) audioFile.getAudioHeader().getBitRateAsNumber();
                length = audioFile.getAudioHeader().getTrackLength();
                encodingType = audioFile.getAudioHeader().getEncodingType();
               
                try {
                    String s = tag.getFirst(FieldKey.TRACK);
                    if (s != null && s.length() > 0) {
                        if (s.indexOf("/") > 0)
                            s = s.substring(0, s.indexOf("/"));
                       
                        track = Integer.parseInt(s);
                    }
                       
                } catch (Exception e) {
                    logger.debug("Could not parse track [" + tag.getFirst(FieldKey.TRACK) + "]", e);
                }
            }
        } catch (Exception e) {
            logger.error("Could not parse music file " + filename, e);
        }
View Full Code Here


    File rawFile = rawDocument.getContentAsFile(false);
    try {
      AudioFile audioFile = AudioFileIO.read(rawFile);
      ArrayList<String> info = new ArrayList<String>();

      Tag tag = audioFile.getTag();

      info.add(tag.getFirst(FieldKey.ARTIST).trim());
      info.add(tag.getFirst(FieldKey.ALBUM).trim());
      info.add(tag.getFirst(FieldKey.TITLE).trim());

      try {
        int year = new Integer(tag.getFirst(FieldKey.YEAR).trim()).intValue();
        if (year > 0) {
          info.add(tag.getFirst(FieldKey.YEAR).trim());
        }
      } catch (Exception ex) {
      }
      int length = audioFile.getAudioHeader().getTrackLength();
      int hours, minutes, seconds;
View Full Code Here

    try {
      AudioFile audioFile = AudioFileIO.read(new java.io.File(
          file.getDirectory(), file.getFilename()));
     
      Tag tag = audioFile.getTag();
      if (tag != null) {
        metaData.setArtist(getTagField(tag, ARTIST));
        metaData.setArtistSort(getTagField(tag, ARTIST_SORT));
        metaData.setAlbumArtist(toAlbumArtist(tag));
        metaData.setAlbumArtistSort(getTagField(tag, ALBUM_ARTIST_SORT));
        metaData.setAlbum(toAlbum(getTagField(tag, ALBUM)));
        metaData.setTitle(getTagField(tag, TITLE));
        metaData.setYear(getTagField(tag, YEAR));
        metaData.setGenre(toGenre(getTagField(tag, GENRE)));
        metaData.setLyrics(getTagField(tag, LYRICS));
        metaData.setComposer(getTagField(tag, COMPOSER));
        metaData.setDiscNr(toFirstNumber(getTagField(tag, DISC_NO)));
        metaData.setDiscNrs(toShort(getTagField(tag, DISC_TOTAL)));
        metaData.setTrackNr(toFirstNumber(getTagField(tag, TRACK)));
        metaData.setTrackNrs(toShort(getTagField(tag, TRACK_TOTAL)));
        metaData.setCoverArtEmbedded(tag.getFirstArtwork() != null);
      }

      AudioHeader audioHeader = audioFile.getAudioHeader();
      if (audioHeader != null) {
        metaData.setVbr(audioHeader.isVariableBitRate());
View Full Code Here

  public boolean isAudioFile(String extension) {
    return extension != null && ALLOWED_EXTENSIONS.contains(extension.toUpperCase());
  }
 
    public Artwork getArtwork(java.io.File file) throws ApplicationException {
      Tag tag = null;
      try {
        AudioFile audioFile = AudioFileIO.read(file);
        tag = audioFile.getTag();
      } catch (CannotReadException | IOException | TagException
          | ReadOnlyFileException | InvalidAudioFrameException
          | RuntimeException e) {
        throw new ApplicationException("Failed reading artwork from file " + file, e);
      }
        return tag == null ? null : tag.getFirstArtwork();
    }
View Full Code Here

            result.setSmdID(getSmdId(file));
            result.setTags(new ArrayList<TagData>());
            Map<String, List<String>> normalTags = new HashMap<String, List<String>>();
            Map<String, List<String>> sortTags = new HashMap<String, List<String>>();
            AudioFile f = AudioFileIO.read(file);
            Tag tag = f.getTag();
            Iterator<TagField> it = tag.getFields();
            while (it.hasNext()) {
                TagField tf = it.next();
                TagData tagData = getTagData(tf);
                if (tagData != null) {
                    String[] values;
View Full Code Here

  public void mp3TagReadeTest() {
    File testFile = new File("src/com/life/audiotageditor/test/test.mp3"); //$NON-NLS-1$

    try {
      AudioFile audioFile = AudioFileIO.read(testFile);
      Tag tag = audioFile.getTag();
      if (tag instanceof ID3v1Tag) {
        ID3v1Tag v1tag = (ID3v1Tag) tag;
        String title = v1tag.getFirst(FieldKey.TITLE);
        System.out.println(title);
      }
View Full Code Here

  public void mp3TagWriteTest() {
    File testFile = new File("src/com/life/audiotageditor/test/test.mp3"); //$NON-NLS-1$

    try {
      AudioFile audioFile = AudioFileIO.read(testFile);
      Tag tagv1 = new ID3v1Tag();
      tagv1.setField(FieldKey.ALBUM, "New Concept Engl"); //$NON-NLS-1$
      tagv1.setField(FieldKey.TITLE, "New Concept Engli"); //$NON-NLS-1$
      tagv1.setField(FieldKey.ARTIST, "New Concept Englis"); //$NON-NLS-1$
      audioFile.setTag(tagv1);

      Tag tagv23 = new ID3v23Tag();
      tagv23.setField(FieldKey.ALBUM, "New Concept En"); //$NON-NLS-1$
      tagv23.setField(FieldKey.TITLE, "New Concept En"); //$NON-NLS-1$
      tagv23.setField(FieldKey.ARTIST, "New Concept "); //$NON-NLS-1$
      tagv23.setField(FieldKey.TRACK, "1"); //$NON-NLS-1$
      audioFile.setTag(tagv23);

      AudioFileIO.write(audioFile);
    } catch (CannotReadException e) {
      e.printStackTrace();
View Full Code Here

    }
  }

  public static void saveAudioFile(AudioFile audioFile, AudioTag audioTag) {
    try {
      Tag tagv1 = new ID3v1Tag();
      tagv1.setField(FieldKey.TITLE, audioTag.getTitle());
      tagv1.setField(FieldKey.ARTIST, audioTag.getArtist());
      tagv1.setField(FieldKey.ALBUM, audioTag.getAlbum());
      tagv1.setField(FieldKey.YEAR, audioTag.getYear());
      tagv1.setField(FieldKey.GENRE, audioTag.getGenre());
      tagv1.setField(FieldKey.COMMENT, audioTag.getComment());
      audioFile.setTag(tagv1);

      Tag tagv23 = new ID3v23Tag();
      tagv23.setField(FieldKey.ALBUM, audioTag.getAlbum());
      tagv23.setField(FieldKey.TITLE, audioTag.getTitle());
      tagv23.setField(FieldKey.ARTIST, audioTag.getArtist());
      if (!audioTag.getTrack().isEmpty()) {
        tagv23.setField(FieldKey.TRACK, audioTag.getTrack());
      }
      tagv23.setField(FieldKey.YEAR, audioTag.getYear());
      tagv23.setField(FieldKey.GENRE, audioTag.getGenre());
      tagv23.setField(FieldKey.COMMENT, audioTag.getComment());
      tagv23.setField(FieldKey.ALBUM_ARTIST, audioTag.getAlbumArtist());
      audioFile.setTag(tagv23);

      AudioFileIO.write(audioFile);
    } catch (TagException e) {
      e.printStackTrace();
View Full Code Here

  private void readTagsFromFile() {
    try {
      AudioFile f = AudioFileIO.read(new File(_fileName));
     
      AudioHeader ah = f.getAudioHeader();
      Tag tag = f.getTag();
     
      _title = tag.getFirstTitle();
      _artist = tag.getFirstArtist();
      _album = tag.getFirstAlbum();
      _trackNumber = tag.getFirstTrack();
      _trackLength = ah.getTrackLength()
      _genre = tag.getFirstGenre();
      _year = tag.getFirstYear()
      _comment = tag.getFirstComment();

    } catch (Exception e) {
      Log.getInstance(AudioItem.class).warn("Error while reading file properties : " + _fileName + " (" + e.toString() +")."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    } finally {
     
View Full Code Here

    String comment = ""; //$NON-NLS-1$
    try {
      AudioFile f = AudioFileIO.read(new File(fileName));
     
      AudioHeader ah = f.getAudioHeader();
      Tag tag = f.getTag();
     
      try {
        title = tag.getFirstTitle().replaceAll("'", "''"); //$NON-NLS-1$ //$NON-NLS-2$
      } catch (Exception e) {
        Log.getInstance(PlaylistController.class).warn("Error while reading title property : " + fileName + " (" + e.toString() +")."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
      try {
        artist = tag.getFirstArtist().replaceAll("'", "''"); //$NON-NLS-1$ //$NON-NLS-2$
      } catch (Exception e) {
        Log.getInstance(PlaylistController.class).warn("Error while reading artist property : " + fileName + " (" + e.toString() +")."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
      try {
        album = tag.getFirstAlbum().replaceAll("'", "''"); //$NON-NLS-1$ //$NON-NLS-2$
      } catch (Exception e) {
        Log.getInstance(PlaylistController.class).warn("Error while reading album property : " + fileName + " (" + e.toString() +")."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
      try {
        trackNumber = tag.getFirstTrack().replaceAll("'", "''");       //$NON-NLS-1$ //$NON-NLS-2$
      } catch (Exception e) {
        Log.getInstance(PlaylistController.class).warn("Error while reading trackNumber property : " + fileName + " (" + e.toString() +")."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
      try {
        trackLength = ah.getTrackLength();
      } catch (Exception e) {
        Log.getInstance(PlaylistController.class).warn("Error while reading trackLength property : " + fileName + " (" + e.toString() +")."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
      try {
        genre = tag.getFirstGenre().replaceAll("'", "''"); //$NON-NLS-1$ //$NON-NLS-2$
      } catch (Exception e) {
        Log.getInstance(PlaylistController.class).warn("Error while reading genre property : " + fileName + " (" + e.toString() +")."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
      try {
        year = tag.getFirstYear().replaceAll("'", "''"); //$NON-NLS-1$ //$NON-NLS-2$
      } catch (Exception e) {
        Log.getInstance(PlaylistController.class).warn("Error while reading year property : " + fileName + " (" + e.toString() +")."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
      try {
        comment = tag.getFirstComment().replaceAll("'", "''"); //$NON-NLS-1$ //$NON-NLS-2$
      } catch (Exception e) {
        Log.getInstance(PlaylistController.class).warn("Error while reading comment property : " + fileName + " (" + e.toString() +")."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }

    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.jaudiotagger.tag.Tag

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.