2 Replies - 2037 Views - Last Post: 15 November 2012 - 11:47 AM Rate Topic: -----

#1 JeffBurnsRed  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 08-November 12

Reading mp3 Tags from Files

Posted 15 November 2012 - 06:57 AM

I am trying to read mp3 tags from files but I am having trouble. I am trying somethings that I found when researching this but I'm not sure if this is the best option. For example, when I run this program,
import java.io.*;

public class MP3 {
	public static void main(String[] args) {
		try {
			File song = new File("Sublime - Santeria.mp3");
			FileInputStream file = new FileInputStream(song);
			int size = (int)song.length();
			file.skip(size - 128);
			byte[] last128 = new byte[128];
			file.read(last128);
			String id3 = new String(last128);
			String tag = id3.substring(0, 3);
			if (tag.equals("TAG")) {
				System.out.println("Title: " + id3.substring(3, 32));
				System.out.println("Artist: " + id3.substring(33, 62));
				System.out.println("Album: " + id3.substring(63, 91));
				System.out.println("Year: " + id3.substring(93, 97));
			} else
				System.out.println(args[0] + " does not contain" + " ID3 information.");
			file.close();
		} catch (Exception e) {
			System.out.println("Error - " + e.toString());
		}
	}
}


I get the following output:
>javac MP3.java
>Exit code: 0
>java MP3
Title: Santeria
Artist: Sublime
Album: Sublime
Year: 1996

But after the title, artist, and album I get NULNULNULNULNULNUL... for quite a while. I'm not sure if this is because I am just showing the output in a print line statement or if there is another way I could accomplish this task.

Is This A Good Question/Topic? 0
  • +

Replies To: Reading mp3 Tags from Files

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2675
  • View blog
  • Posts: 11,305
  • Joined: 20-September 08

Re: Reading mp3 Tags from Files

Posted 15 November 2012 - 08:07 AM

Don't reinvent the wheel ;) e.g.
http://javamusictag.sourceforge.net/
Was This Post Helpful? 2
  • +
  • -

#3 JeffBurnsRed  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 08-November 12

Re: Reading mp3 Tags from Files

Posted 15 November 2012 - 11:47 AM

Thanks for the suggestion :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1