My JavaFX MP3 Player 2("Displaying METADATA")

My JavaFX MP3 Player 2("Displaying  METADATA")

This is a continuation of my javafx player ,you can check my previous post on javafx mp3 player here .This is a new implementation that adds a new capability to my media player  that is displaying a file's metadata (data that describes a file )in our case an mp3 file.I just added a VBox with labels and an imageview to my previous javafx player, that displays the metadata,
The data might be artist,year,album,genre,album cover and many more.You can get more info about ID3 tag  at Wikipedia.

A screenshot of the new Implementation.



Code snippets

Javafx Media class has a method that gets metadata and returns the metadata in an ObservableMap<String,Object>.

Heres an basic example of my method i only need album,artist,title,year,album cover metadata.

      Media media=new Media("mp3 file");

     ObservableMap<String,Object> meta_data=media.getMetadata();

     meta_data.addListener(new MapChangeListener<String,Object>(){
          @Override
          public void onChanged(Change<? extends String, ? extends Object> ch) {  
     
             if(ch.wasAdded()){

                   String key=ch.getKey();
                   Object value=ch.getValueAdded();

             switch(key){
               case "album":
                   album.setText("Album: "+value.toString());
                   break;
               case "artist":  
                   artist.setText("Artist: "+value.toString());
                   break;
               case "title":
                   title.setText("Title: "+value.toString());
                   break;
               case "year":
                   year.setText("Year: "+value.toString());
                   break;
               case "image":
                   album_cover.setImage((Image)value);
                   break;
           }
              }
          }
     });

Video sample


Comments

Popular Posts