?
Solved

reading mp3 id3 tags in java...

Posted on 2001-06-04
8
Medium Priority
?
466 Views
Last Modified: 2010-03-31
I am trying to figure out how to read the id3 tag of an mp3 file with java. I think it is a fixed width thing at the end of the file... so is there a way to open a file and get to the end and work backwards or something?
0
Comment
Question by:AndyBeckwith
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 5

Expert Comment

by:Droby10
ID: 6154612
sure...it's been awhile, i'm going off the top of my head, and i don't have a reference available...so this may be a little off.

import java.io.*;

public static void main ( String args[] ) {
  try {
    File f = new File ( args[0] );
    FileInputStream fis = new FileInputStream ( f );
    int flen = fis.available();
    byte sig[] = new byte [ 3 ];
    byte artist[] = new byte [ 30 ];
    byte title[] = new byte [ 30 ];
    byte album[] = new byte [30];
    byte genre[] = new byte [1];
    byte comments = new byte [30];

    int id3len = sig.length + artist.length + title.length + album.length + genre.length + comment.length;

    fis.skip ( len - id3len );    
    fis.read ( sig );
    fis.read ( artist );
    fis.read ( title );
    fis.read ( album );
    fis.read ( genre );
    fis.read ( comments );
  } catch ( Exception e ) {
    e.printStackTrace();
  }
}


also, this code is for id3 version 1 only...which isn't used as much anymore...

id3 version 2 allowed title-streaming, embeded content...etc, and is much more robust...it's also much more difficult to filter as its embeded within the frames of an mp3 document.

0
 
LVL 5

Expert Comment

by:Droby10
ID: 6154619
just realized how ugly the code was...be sure to check verify after all of the reads...and close the inputstream at the end.
0
 

Author Comment

by:AndyBeckwith
ID: 6154690
do you have any info on the v2 tags?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Expert Comment

by:Droby10
ID: 6154714
no...but here's the definitive resource..

http://www.id3.org/
http://www.id3.org/develop.html
http://www.id3.org/id3v2.4.0-structure.txt

you'll also find links for source documentation at

http://id3lib.sourceforge.net/

-hope this helps.
0
 
LVL 5

Expert Comment

by:Droby10
ID: 6154718
and actually here's some java source...

http://www.rabbitfarm.com/site/id3.html

0
 

Author Comment

by:AndyBeckwith
ID: 6155273
Back to your original code...

This is what I did, and it still wont work...

~~~ code ~~~
import java.io.*;
public class ReadId3 {

  public static void main ( String args[] ) {
    try {
      File f = new File ( args[0] );
      FileInputStream fis = new FileInputStream ( f );
      int flen = fis.available();
      byte [] sig = new byte [ 3 ];
      byte artist[] = new byte [ 30 ];
      byte [] title = new byte [ 30 ];
      byte album[] = new byte [30];
      byte genre[] = new byte [1];
      byte comments[] = new byte [30];

      int id3len = 124;

      fis.skip ( flen - id3len );    
      fis.read ( sig );
      fis.read ( artist );
      fis.read ( title );
      fis.read ( album );
      fis.read ( genre );
      fis.read ( comments );
    } catch ( Exception e ) {
      e.printStackTrace();
    }

    for( int i = 0; i < 30; i++ ){
      System.out.print( "" + title[ i ] );
    }
     
  }
}
~~~ end code ~~~

I still get this error:

~~~ error ~~~
ReadId3.java:31: cannot resolve symbol
symbol  : variable title
location: class ReadId3
        System.out.print( "" + title[ i ] );
                               ^
1 error
~~~ end error ~~~

I cant seem to force it to a string...
0
 
LVL 5

Accepted Solution

by:
Droby10 earned 400 total points
ID: 6155911
your print statement is outside of the try loop where title is defined...title is out-of-scope...if you predeclare it, it should work.

import java.io.*;
public class ReadId3 {

 public static void main ( String args[] ) {
   byte [] sig = new byte [ 3 ];
   byte artist[] = new byte [ 30 ];
   byte [] title = new byte [ 30 ];
   byte album[] = new byte [30];
   byte genre[] = new byte [1];
   byte comments[] = new byte [30];
   try {
     File f = new File ( args[0] );
     FileInputStream fis = new FileInputStream ( f );
     int flen = fis.available();
     int id3len = 124;

     fis.skip ( flen - id3len );    
     fis.read ( sig );
     fis.read ( artist );
     fis.read ( title );
     fis.read ( album );
     fis.read ( genre );
     fis.read ( comments );
   } catch ( Exception e ) {
     e.printStackTrace();
   }

   for( int i = 0; i < 30; i++ ){
     System.out.print( "" + title[ i ] );
   }
   
 }
}
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 8898913


No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


--  Points to Droby10


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question