The final step in integrating Jukebox with your game is to use the Jukebox.IControl interface to:

  • Co-ordinate playback of multiple Playlists
  • Expose information about the currently playing track
  • Route user input to the Jukebox plug-in to skip tracks and provide feedback on which tracks are liked or disliked by the gamer.

Jukebox.IControl is a singleton object, and may either be instantiated via the Jukebox Control helper script (for plumbing into the game’s UX) or else obtained as necessary in order to switch between playlists.

Switching Between Playlists

If you have multiple Jukebox.IPlaylist objects (or Jukebox Playlist scripts) declared in your scene, then you should use the Jukebox.IControl interface to specify which one is currently active. When a playlist needs to become the active playlist, it should be assigned to the CurrentPlaylist property of the Jukebox.IControl interface. If you do this then the previous playlist will be automatically stopped, and playback will be started on the new playlist. Switching between playlists this way allows the Jukebox plug-in to keep track of which tracks are being played by the gamer, and so better target music to match the gamer’s preference.

See the Music Control demo script, provided in both Jukebox demo packages, for an example of how this is achieved.

Routing User-Feedback to the Jukebox Plug-in

The Jukebox.IControl interface has three methods to allow user feedback to be routed back to Jukebox: SkipCurrentTrack, LikeCurrentTrack and DislikeCurrentTrack. Use of these methods are important to optimize the gamer’s experience – firstly to enable them to skip tracks they don’t like; and secondly, to allow Jukebox to build up a profile of the gamer’s likes and dislikes, so that the music selection can be optimized to give the user tracks they will enjoy listening to.

The Jukebox Control script contains a simple implementation of how this feedback can be gathered and routed to the underlying Jukebox.IControl interface; and you are free to modify and/or replace this script with your own.

Exposing Currently-Playing Track Information

The Jukebox.IControl interface has a number of properties that expose information about the currently playing track; and it also emits an OnNewTrack event whenever the track changes. This is to allow the game to provide this information to the gamer via its own UX. The Jukebox Control script, provided in both Jukebox demo packages, provides an example of how this may be connected to your game:

  1. Declare an instance of the Jukebox Control script within your scene.
  2. Create a Unity Text object and set it up as a 2D overlay in your scene (for an example see the full Jukebox Demo package here).
  3. In the Jukebox Control’s property box, assign your newly created Text object as the Display Text property, as follows: 

Once you have completed this step, and assuming your Text object is correctly positioned in relation to the camera, the Jukebox Control script will display a simple summary of the currently playing track, along with its playback progress as a percentage. Once you understand what is going on, this script may be modified or replaced in order to integrate more appropriately with your game’s UX.