Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

[JAVA] Reading in MP3 ID3 tags.

Options
  • 24-02-2006 12:36am
    #1
    Registered Users Posts: 11,980 ✭✭✭✭


    I'm trying to figure out what is the best approach to reading ID3 tags with Java. Opening an MP3 file shows the ID3 tag in the first few bytes of the file. Is there anyway to parse this with delimiters? Bearing in mind I want to write it myself from scratch, but some pointers would be appreciated.


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


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

    Basically, parse out the data between bytes ID3 and 3DI and you have your ID3 frame. After that its a case of following the specification above.


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    id31 tags are easy, to write a full ID3V2 tag reader is a fair bit more complicated. Unless you want to do this for the fun of it, just get a library written by someone else.


  • Registered Users Posts: 919 ✭✭✭timeout


    id31 tags are easy, to write a full ID3V2 tag reader is a fair bit more complicated. Unless you want to do this for the fun of it, just get a library written by someone else.

    And on that note take a look at http://sourceforge.net/projects/jd3lib/

    If you don't want to use it then take a look at how they went about coding it. You might find it useful or be able to improve on it.

    Timeout


  • Registered Users Posts: 11,980 ✭✭✭✭Giblet


    Hey if anyone is interest in how I did it, this is for my 2nd year project, just a little extra I added on top of the design spec.
    public String scanID3Field(int byteStart,int end) throws IOException
    	{				
    		File f;	
    		String field="";
    		f = new File(this.getFile());			
    		raf = new RandomAccessFile(f, "r");		
    		byte [] tagBytes = new byte[30];		
    		this.setPointer(byteStart,f);
    		raf.read(tagBytes,0,end);	//0 signifies it will start at the newly set pointer position	
    		for (int i = 0;i < tagBytes.length; i++)
    		{
    			field += (char)tagBytes[i];		//parse the characters into a string	
    		}		
    		return field; 		
    	}	
    

    Basically, using some getters for the artist, name etc I set a variable which sets the pointer to the relevant place for that information using bytestart which is defined in the getter. It also has a "length" variable which is also defined in the getter which reads x amount of bytes. Now I have the relevant information stored in each instance variable. I just need to tokenise it. It works very well for anything with an ID3v1 tag. There's a lot more involved, this is just a nice addition. I'm also going to set the array size for storing each field or maybe use a vector.


Advertisement