Skip to content

Media Controller update title, artist and artwork uri  #910

@LovroLudvig

Description

@LovroLudvig

Im using the MediaController and MediaLibraryService to play live stream music from a stream. The media notification should show the currently playing song info and I implemented the updating of the notification like this:

viewModel.updateNotification?.collect { audioSource ->
  mediaController?.setMediaItem(audioSource.toMediaItem())
}

private fun AudioSource.toMediaItem() = MediaItem.Builder()
  .setMediaMetadata(toMetadata())
  .setUri(contentUrl)
  .build()

private fun AudioSource.toMetadata() =
  MediaMetadata.Builder()
    .setTitle(albumName)
    .setArtist(artistName)
    .setArtworkUri(image)
    .build()

But each time I change the media item like this when the song updates there is a short break in playback even though the URL of the stream stayed the same.

Is there an option to update just the metadata? So that the texts and images are changed but the stream remains intact something like:

viewModel.updateNotification?.collect { audioSource ->
  mediaController?.updateMetadata(audioSource.toMetadata())
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions