4

I'm building a music player for Android, using these two samples (Android MediaBrowserService Sample and Universal Music Player) as examples. I noticed both load media information on start-up and add it to the Media Browser. Both have the complete media list available at start-up.

But what if I want to add media to the player queue dynamically?

For example, I'm using Spotify's Web API to retrieve a list of tracks based on the user's query. Among other things, it returns a link to a 30s preview of the track. As far as I understood, I need to create a MediaMetadata object containing this track.

But then, how should I add this information to the MediaBrowserService? The desired behavior is that when the user clicks on the play button for one of the tracks in the list (RecyclerView), only that track is played. Also, I'm not using the browsing components to represent content hierarchy.

How can I implement this behavior? Which references should I read?

Thanks in advance.

Community
  • 1
  • 1
Vin
  • 309
  • 1
  • 11

1 Answers1

0

My thinking is, if you are using MediaControllerCompat, then you can easily call MediaControllerCompat.getMediaController(Activity).getTransportControls().playFromUrl(Url) or playFromMediaId(String) depending on which you have configured. You must have setup your media session and MediaSessionCompat.Callback to this.

odifek
  • 180
  • 13