I'm trying to create a basic Media Player in JavaFX. I finally made it possible to display the album cover based on the metadata on the file.
However on some songs it doesn't show anything, even if I know that there is an album cover.
Here theres no problem:
However when I select another file it just looks like this:
I swear the only thing I'm changing is the name of the song. Both of the files are formatted in MP3 and have a 500x500 jpg as album cover. The song plays succesfully. Meaning that the file exist. But no album cover
the me variable is the Media which contains the file.
This is the method I'm using to display the album cover in the program:
private void displayAlbumCover (){
// Will start to show a blank CD
File file = new File("src/sample/images/blank_cd.jpeg");
Image image = new Image(file.toURI().toString());
albumCoverView.setImage(image);
// However if an album cover is found in the meta-data it will be displayed
ObservableMap<String,Object> meta_data=me.getMetadata();
meta_data.addListener((MapChangeListener<String, Object>) ch -> {
if(ch.wasAdded()){
String key=ch.getKey();
Object value=ch.getValueAdded();
if (key.equals("image")){
// If there's an album cover in the metadata it will be displayed
albumCoverView.setImage((Image)value);
System.out.println("Found album cover");
}
}
});
}