Package org.farng.mp3

Examples of org.farng.mp3.AbstractMP3Tag


      duration = (long) ((double) ioFile.length() / ((double) mp3.getBitRate() / 8.0));
    }
    bitrate = mp3.getBitRate();
    frequency = mp3.getFrequency();
    // get the id3 tags
    AbstractMP3Tag tag = null;
    if (mp3.hasID3v1Tag()) {
      tag = mp3.getID3v1Tag();

      title = tag.getSongTitle();
      if(!"New Artist".equals( tag.getLeadArtist())){
        artist = tag.getLeadArtist();
      }
      if(!"New Title".equals( tag.getAlbumTitle())){
        album = tag.getAlbumTitle();
      }
      year = tag.getYearReleased();
      genre = lookupGenre(tag.getSongGenre());

    }
    if (mp3.hasID3v2Tag()) {
      tag = mp3.getID3v2Tag();
      if (title == null)
        title = tag.getSongTitle();
      if (artist == null && !"New Artist".equals( tag.getLeadArtist()))
        artist = tag.getLeadArtist();
      if (album == null && !"New Title".equals( tag.getAlbumTitle()))
        album = tag.getAlbumTitle();
      if (year == null)
        year = tag.getYearReleased();
      if (genre == null)
        genre = lookupGenre(tag.getSongGenre());

    }
  }
View Full Code Here


   * Construst a SongData from an MP3 at the given absolute path
   * @param path the absolute path of the MP3
   */
  public SongData( String path ) throws SongDataException {
    this.path = tagPrep(path);
    AbstractMP3Tag tag = null;
        try {
      MP3File mp3file = new MP3File(path);
      if (mp3file.hasID3v2Tag()) {
        tag = mp3file.getID3v2Tag();
      } else if (mp3file.hasID3v1Tag()) {
        tag = mp3file.getID3v1Tag();
      } else {
        throw new SongDataException( "No MP3 ID tag found for \""+path+"\"" );
      }
        } catch (TagException tE) {
            throw new SongDataException( "(TagException) Broken MP3 ID tag found for \""+path+"\"" );
        } catch (IOException ioE) {
            log.warn("", ioE);
            throw new SongDataException( "IOE for \""+path+"\"" );
    }

    try { //unfortunately jd3lib isn't perfect...grr...
      title = tagPrep(tag.getSongTitle());
      album = tagPrep(tag.getAlbumTitle());
      artist = tagPrep(tag.getLeadArtist());
            genre = tagPrep(tag.getSongGenre());
            if (genre.length() > 1) { // ensure that genres do not have mutiples because of case
                char firstChar = genre.toUpperCase().charAt(0);
                genre = firstChar+genre.substring(1);
            }
            track = Integer.parseInt(tag.getTrackNumberOnAlbum());

        } catch (NullPointerException npE) {
      throw new SongDataException( "(NPE) Broken MP3 ID tag found for \""+path+"\"" );
    } catch (NumberFormatException nfE) {
            log.warn("No track number for " + title);
View Full Code Here

        // read the 5 character size
        file.read(buffer, 0, 5);
        final int size = Integer.parseInt(new String(buffer, 0, 5));
        if ((size == 0) && (TagOptionSingleton.getInstance().isLyrics3KeepEmptyFieldIfRead() == false)) {
            throw new InvalidTagException("Lyircs3v2 Field has size of zero.");
        }
        buffer = new byte[size];

        // read the SIZE length description
        file.read(buffer);
View Full Code Here

        // read the 5 character size
        file.read(buffer, 0, 5);
        final int size = Integer.parseInt(new String(buffer, 0, 5));
        if ((size == 0) && (TagOptionSingleton.getInstance().isLyrics3KeepEmptyFieldIfRead() == false)) {
            throw new InvalidTagException("Lyircs3v2 Field has size of zero.");
        }
        buffer = new byte[size];

        // read the SIZE length description
        file.read(buffer);
View Full Code Here

        final String identifier = new String(buffer, 0, 4);

        // is this a valid identifier?
        if (isValidID3v2FrameIdentifier(identifier) == false) {
            file.seek(file.getFilePointer() - 3);
            throw new InvalidTagException(identifier + " is not a valid ID3v2.30 frame");
        }
        filePointer = file.getFilePointer();

        // skip the 4 byte size
        file.skipBytes(4);
View Full Code Here

        // read the 5 character size
        file.read(buffer, 0, 5);
        final int size = Integer.parseInt(new String(buffer, 0, 5));
        if ((size == 0) && (TagOptionSingleton.getInstance().isLyrics3KeepEmptyFieldIfRead() == false)) {
            throw new InvalidTagException("Lyircs3v2 Field has size of zero.");
        }
        buffer = new byte[size];

        // read the SIZE length description
        file.read(buffer);
View Full Code Here

        // read the 5 character size
        file.read(buffer, 0, 5);
        final int size = Integer.parseInt(new String(buffer, 0, 5));
        if ((size == 0) && (TagOptionSingleton.getInstance().isLyrics3KeepEmptyFieldIfRead() == false)) {
            throw new InvalidTagException("Lyircs3v2 Field has size of zero.");
        }
        buffer = new byte[size];

        // read the SIZE length description
        file.read(buffer);
View Full Code Here

            // int is 4 bytes.
            final int extendedHeaderSize = file.readInt();

            // the extended header must be atleast 6 bytes
            if (extendedHeaderSize <= 6) {
                throw new InvalidTagException("Invalid Extended Header Size.");
            }
            final byte numberOfFlagBytes = file.readByte();

            // read the flag bytes
            file.read(buffer, 0, numberOfFlagBytes);
View Full Code Here

        // read the 5 character size
        file.read(buffer, 0, 5);
        size = Integer.parseInt(new String(buffer, 0, 5));
        if ((size == 0) && (TagOptionSingleton.getInstance().isLyrics3KeepEmptyFieldIfRead() == false)) {
            throw new InvalidTagException("Lyircs3v2 Field has size of zero.");
        }
        return size;
    }
View Full Code Here

        file.read(buffer, 0, 3);
        final String identifier = new String(buffer, 0, 3);

        // is this a valid identifier?
        if (TagUtility.isLyrics3v2FieldIdentifier(identifier) == false) {
            throw new InvalidTagException(identifier + " is not a valid ID3v2.4 frame");
        }
        this.setBody(readBody(identifier, file));
    }
View Full Code Here

TOP

Related Classes of org.farng.mp3.AbstractMP3Tag

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.