* returns IDInfo
*/
public IDInfo readID3 (String filePath) throws IOException {
String fileName = null;
BinaryReader in = null;
IDInfo id3 ;
String title = null;
String album = null;
String interpret = null;
int year = 0;
try {
in = new BinaryReader(filePath);
// check for ID3 tag
if (!(in.readASCIChars(3).equals(new String("ID3")))) {
throw new IOException();
}
// check correct version
if(in.read() != 3){
throw new IOException();
}
// skip revision number of version (1 bytes)
in.skip(1);
// read flags (check extended header)
if ((in.read() & 64) == 64) {
// TODO: read extended header and skip extended header and CRC data
System.out.println("ja");
throw new IOException();
}
// skip tag size (4 bytes)
in.skip(4);
String frame_id = in.readASCIChars(4);
System.out.println(frame_id);
// searching for frame_id
//TODO: Interpret hinzufügen, bild
//TODO: in Methode auslagern
while(!( (frame_id.equals(new String("TALB")) || frame_id.equals(new String("TIT2")) || frame_id.equals(new String("TYER")))) ){
// read frame size
long sizeFrameBody = in.read();
sizeFrameBody = sizeFrameBody << 8;
sizeFrameBody += in.read();
sizeFrameBody = sizeFrameBody << 8;
sizeFrameBody += in.read();
sizeFrameBody = sizeFrameBody << 8;
sizeFrameBody += in.read();
//long sizeFrameBody = in.read();
long skippingSize = sizeFrameBody + 2;
//skip frame
in.skip(skippingSize);
frame_id = in.readASCIChars(4);
System.out.println(frame_id);
}
//
if(frame_id.equals(new String("TIT2"))){
title = readSingleInf(in, frame_id);
}
if(frame_id.equals(new String("TALB"))){
album = readSingleInf(in, frame_id);
}
// if(frame_id.equals(new String("TYER")))
// year = (int)readInf(in, frame_id);
else{
System.out.println("nein");
}
} finally {
if (in != null) {
in.close();
}
}
//IDInfo id3 = new IDInfo("sanjeet.mp3","c:\\","Intpret2", "bla bla", "sdfjsdfj", 2011);
id3 = new IDInfo(fileName,filePath, interpret, title, album, year);
System.out.println(filePath +", " + title + ", " + album);
return id3;
}