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;