I'm developing an MP3 player with java, using mp3agic to edit .mp3 files metadata. The problem is: I don't know the specific tags of the files to edit the desired data.
Here's my code to get the mp3 track for example:
public static int get_rep(Music msc)
{
try
{
Mp3File file = new Mp3File(msc.get_path());
if (file.hasId3v1Tag())
{
ID3v1 tag = file.getId3v1Tag();
return Integer.parseInt(tag.getTrack());
}
else if (file.hasId3v2Tag())
{
ID3v2 tag = file.getId3v2Tag();
return Integer.parseInt(tag.getTrack());
}
}
catch (UnsupportedTagException e)
{
e.printStackTrace();
}
catch (InvalidDataException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return -1;
}
Is there a way to get the tag value skipping file.hasId3v1Tag()
and file.hasId3v2Tag()
verifications?
I tried:
private static Object get_tag(Music msc)
{
try
{
Mp3File file = new Mp3File(msc.get_path());
if (file.hasId3v1Tag())
{
return file.getId3v1Tag();
}
else if (file.hasId3v2Tag())
{
return file.getId3v2Tag();
}
/*
else if(file.hasCustomTag())
{
file.removeCustomTag();
return file.getCustomTag();
}
*/
}
catch (UnsupportedTagException e)
{
e.printStackTrace();
}
catch (InvalidDataException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return Boolean.FALSE;
}
But I still have to check the tags, then cast the Object
value to a tag value, which means I'd have to know it anyway. I'm accepting any suggestions, even exchanging mp3agic.
ID3v2
extendsID3v1
, so you should be able to useID3v1 tag = file.getId3v2Tag();
and be able to extract ID3v1 data from it.You could try this: