Package org.jaudiotagger.audio.mp3

Examples of org.jaudiotagger.audio.mp3.MP3File


    this.testID3v2Genre("(13)", "Pop");
  }

  private void testID3v1Genre(String input, String expectedOutput) throws ID3TagFileException {
    ID3v1 id3Mock = EasyMock.createMock(ID3v1.class);
    MP3File mp3FileMock = TagTestHelpLibrary.createMP3FileMockForID3v1(id3Mock);

    EasyMock.expect(id3Mock.getSongGenre()).andReturn(input);
    EasyMock.replay(id3Mock, mp3FileMock);

    ID3Tag tag = jidID3TagFactory.getID3Tag(mp3FileMock);
View Full Code Here


    EasyMock.verify(id3Mock, mp3FileMock);
  }
 
  private void testID3v2Genre(String input, String expectedOutput) throws ID3TagFileException {
    AbstractID3v2 id3Mock = EasyMock.createMock(AbstractID3v2.class);
    MP3File mp3FileMock = TagTestHelpLibrary.createMP3FileMockForID3v2(id3Mock);

    EasyMock.expect(id3Mock.getSongGenre()).andReturn(input);
    EasyMock.replay(id3Mock, mp3FileMock);

    ID3Tag tag = jidID3TagFactory.getID3Tag(mp3FileMock);
View Full Code Here

    jidID3TagFactory.getID3Tag(fileMock);
  }
 
  @Test
  public void ID3v1Test() throws ID3TagFileException{
    MP3File mp3FileMock = TagTestHelpLibrary.createMP3FileMockForID3v1(null);
    EasyMock.replay(mp3FileMock);
   
    ID3Tag id3Tag = jidID3TagFactory.getID3Tag(mp3FileMock);
 
    assertTrue(id3Tag.getClass().equals(ID3v1TagImpl.class));
View Full Code Here

    EasyMock.verify(mp3FileMock);
  }
 
  @Test
  public void ID3v2Test() throws ID3TagFileException{
    MP3File mp3FileMock = TagTestHelpLibrary.createMP3FileMockForID3v2(null);
    EasyMock.replay(mp3FileMock);
   
    ID3Tag id3Tag = jidID3TagFactory.getID3Tag(mp3FileMock);
 
    assertTrue(id3Tag.getClass().equals(ID3v2TagImpl.class));
View Full Code Here

    if (isM4A(file)) {
      throw new ID3M4AException(file);
    }

    try {
      MP3File mp3File = new MP3File(file, NOT_WRITEABLE);
      return getID3Tag(mp3File);

    } catch (IOException e) {
      throw new ID3TagFileException(e, file);
    } catch (TagException e) {
View Full Code Here

   *       </ul>
   */
  public static String[] getIDTags(String file) {
    String[] ret = new String[3];
    try {
      MP3File mp3 = new MP3File(file);
      String mtitle = null, martist=null, malbum=null;
      if(mp3.hasID3v1Tag()) {
        mtitle = mp3.getID3v1Tag().getTitle();
        martist = mp3.getID3v1Tag().getArtist();
        malbum = mp3.getID3v1Tag().getAlbum();
      } else if(mp3.hasID3v2Tag()) {
        mtitle = mp3.getID3v2Tag().getSongTitle();
        martist = mp3.getID3v2Tag().getLeadArtist();
        malbum = mp3.getID3v2Tag().getAlbumTitle();
      }
      ret[0] = toUTF8(martist);
      ret[1] = toUTF8(malbum);
      ret[2] = toUTF8(mtitle);
    } catch (Exception e) {
View Full Code Here

            long totalSamples = trackData.getTotalSamples();
            int enc_delay = GAPLESS_DELAY;

            XingFrame xingFrame = mp3AudioHeader.getXingFrame();
            if (xingFrame != null) {
                LameFrame lameFrame = xingFrame.getLameFrame();
                if (lameFrame != null) {
                    long length = totalSamples;
                    enc_delay += lameFrame.getEncDelay();
                    int enc_padding = lameFrame.getEncPadding() - GAPLESS_DELAY;
                    if (enc_padding < length)
                        length -= enc_padding;

                    if (totalSamples > length)
                        totalSamples = length;
View Full Code Here

    @Override
    protected String getSmdId(File file) throws IOException {
        try {
            AudioFile f = AudioFileIO.read(file);
            MP3AudioHeader header = (MP3AudioHeader) f.getAudioHeader();

            RandomAccessFile randomAccessFile = new RandomAccessFile(file.getCanonicalPath(), "r");
            byte[] tagData = new byte[128];
            randomAccessFile.seek(randomAccessFile.length() - 128);
            randomAccessFile.read(tagData);
            ByteBuffer bBuf = ByteBuffer.allocate(128);
            bBuf.put(tagData);
            bBuf.rewind();
            byte[] tag = new byte[3];
            bBuf.get(tag);
            long length = randomAccessFile.length() - header.getMp3StartByte();
            if (new String(tag).equals("TAG")) {
                length -= 128;
            }
            randomAccessFile.seek(header.getMp3StartByte());
            InputStream is = new BoundedInputStream(new RandomAccessFileInputstream(randomAccessFile), length);
            MessageDigest m = MessageDigest.getInstance("MD5");
            byte[] buffer = new byte[8192];
            int read;
            while ((read = is.read(buffer)) > 0) {
View Full Code Here

                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            MP3AudioHeader mp3AudioHeader = mp3File.getMP3AudioHeader();
            copyHeaderFields(mp3AudioHeader, track);

            long totalSamples = trackData.getTotalSamples();
            int enc_delay = GAPLESS_DELAY;

            XingFrame xingFrame = mp3AudioHeader.getXingFrame();
            if (xingFrame != null) {
                LameFrame lameFrame = xingFrame.getLameFrame();
                if (lameFrame != null) {
                    long length = totalSamples;
                    enc_delay += lameFrame.getEncDelay();
View Full Code Here

  @Override
  public void prepare(RawDocument rawDocument) throws RegainException {

    File rawFile = rawDocument.getContentAsFile(false);
    try {
      MP3File mp3file = new MP3File(rawFile);
      ArrayList<String> info = new ArrayList<String>();

      if (mp3file.hasID3v2Tag()) {
        ID3v24Tag id3v24tag = mp3file.getID3v2TagAsv24();

        info.add(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_ARTIST).trim());
        info.add(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_ALBUM).trim());
        info.add(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_TITLE).trim());
        try {
          int year = new Integer(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_YEAR).trim()).intValue();
          if (year > 0) {
            info.add(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_YEAR).trim());
          }
        } catch (Exception ex) {
        }
        info.add(mp3file.getMP3AudioHeader().getTrackLengthAsString().trim());
        info.add(mp3file.getMP3AudioHeader().getBitRate().trim() + "kbps");

        setCleanedContent(concatenateStringParts(info, Integer.MAX_VALUE));
        setTitle(concatenateStringParts(info, 2));

      } else if (mp3file.hasID3v1Tag()) {
        ID3v1Tag tag = mp3file.getID3v1Tag();

        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) {
        }
        info.add(mp3file.getMP3AudioHeader().getTrackLengthAsString().trim());
        info.add(mp3file.getMP3AudioHeader().getBitRate().trim() + "kbps");

        setCleanedContent(concatenateStringParts(info, Integer.MAX_VALUE));
        setTitle(concatenateStringParts(info, 2));

      } else {
View Full Code Here

TOP

Related Classes of org.jaudiotagger.audio.mp3.MP3File

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.