Registering your music application
In order to integrate your music application with the Unity Sound Menu, you will need first register it by creating a new libunityÂ MusicPlayerÂ instance from inside your program:
var player = new MusicPlayer ("rhythmbox.desktop");
Once your application has been registered, the Sound Menu will keep it’s entry in the menu even after it has been closed, giving users a quick way to launch it again.
Setting current track information
When your application is running, you can send the Sound Menu information about the current track by creating a newÂ TrackMetadataÂ instance and setting it to theÂ current_trackÂ attribute of theÂ MusicPlayerÂ instance you created:
TrackMetadata metadata = new TrackMetadata(); metadata.artist = "Autechre"; metadata.album = "LP5"; metadata.title = "Rae"; player.current_track = metadata;
If your application supports playlists, you can display them in the Sound Menu to let the user switch between them.
var player = new MusicPlayer ("rhythmbox.desktop"); Playlist pl = new Playlist ("fake-pl-id"); pl.name = "yellow swans like"; pl.icon = Icon.new_for_string("audio-volume-high"); player.add_playlist(pl);
You then need connect your application listed to theÂ activate_playlistÂ signal of theÂ MusicPlayer. Each playlist should have a unique id string, as this will be passed to your callback function when the user selects it from the Sound Menu. You can also give your playlist a name and custom icon to be displayed.
You can also set a specific playlist as being used:
player.current_playlist = pl;