2

I do have my own application for media playback - it's using MediaSessionCompat (with combination with ExoPlayer and it's MediaSessionConnector plugin).

On Samsung phone I experience a small issue with AOD (Always On Display) and lock screen. Both contains a small media controller (three buttons) and track title and album - I assume it works with MediaSession.

My problem is that it always shows Unknown / Unknown for title / album (but buttons are working correctly). I'm sure that I'm feeding correctly MediaSession metadata, as it is used in Activities, where using onMetadataChange callback and it contains correct title.

I'm somehow lost, not sure where to look for issue and fix. It's clearly in my app, because other players are working fine (showing title on AOD), but I do not know what else I need to do apart of settings metadata in MediaSession?

Ivan
  • 960
  • 7
  • 15

2 Answers2

8

So shortly

Exoplayer uses MediaDescriptionCompat to get meta from play queue. Then it maps it to MediaMetadataCompat and title is mapped to key MEDIA_KEY_DISPLAY_TITLE , where Samsung is using key MEDIA_KEY_TITLE only. Solution was to add MEDIA_KEY_TITLE to MediaDescriptionCompat.extras.

Another item displayed in Samsung AOD, lock screen is MediaMetadataCompat.METADATA_KEY_ARTIST

Another example of useless complexity in Android - why we need to two classes for metadata, which are almost the same MediaMetadataCompat vs MediaDescriptionCompat?

Ivan
  • 960
  • 7
  • 15
3

@Ivan's answer worked for me. Here is an example in Kotlin:

   mediaSessionConnector = MediaSessionConnector(mediaSession).also {
        it.setPlayer(player)
    }
    mediaSessionConnector.setQueueNavigator(object : TimelineQueueNavigator(mediaSession){
        override fun getMediaDescription(player: Player, windowIndex: Int): MediaDescriptionCompat {
            val extra = Bundle()
            extra.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, "podcastEpisode")
            return MediaDescriptionCompat.Builder().setExtras(extra).setTitle("podcastTitle").build()
        }
    })

This issue was also very helpful.

Supra_01
  • 134
  • 1
  • 6
  • I was setting metadata on the media session instance, but it was showing unknown / not provided while switching videos. The `setQueueNavigator` allowed me to define a "loading" placeholder for such state. – JCarlosR Jan 25 '22 at 04:03