Search code examples
javajavafxmedia-playermp3metadata

Reading ID3v2 tags from MP3 using JavaFX MediaPlayer


I've got some MP3's that were previously not giving me issues reading metadata. Using JavaFX's MediaPlayer.getMetadata() function, I grab all the data from the mp3 file and store it in an ObservableMap<String, Object> map. This worked just great, and then I started using different MP3s.

The standard is obviously ID3v2, but I cannot find any documentation in regards to the getMetadata function and which kinds of tags it parses, and what types it prioritizes over others. Right now I can manage to get Artist, Album, Title, and Album Artist, but the other tags like Track and Track Count are no longer functioning. When I load the metadata, I first print out a call to data.toString(). The data object is the ObservableMap<String, Object> map. It prints nicely formatted, as seen here:

{album artist=LCD Soundsystem, artist=LCD Soundsystem, raw metadata={ID3=java.nio.HeapByteBufferR[pos=221 lim=4096 cap=4096]}, title=You Wanted a Hit, album=This Is Happening}

The MP3s I used before had the track, track total, year, and other metadata in this map, and I cannot find out why they will no longer read. I tried, in my MP3 tag editor, to save to ALL formats of tags (including ID3v1, ID3v2, and APE) but it still refuses to load those particular tags.

I still haven't managed to find any documentation past the regular Oracle javadoc for the getMetadata function, if anyone could point me in the right direction that'd be lovely.


Solution

  • Looks like I figured out the issue. The tag utility I was using was defaulting to ID3v2.3@utf16. I used MP3Tag to convert them to ID3v2.4@utf8. All fields are properly loaded now.

    If anyone can chime in with any extra documentation on what datatypes are returned in the map or what other tags it will return would be great.