google / google/ExoPlayer

Custom MediaDescriptionAdapter ContentTitle being Overloaded elsewhere

Open
#9,857 7 comments 0 reactions 1 assignee Claimed by @marcbaechinger View on GitHub
question
Dominant language
Java
Stars
21.9k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Hello, While working with Exoplayer for media playing I have come across a weird behaviour where the MediaDescriptionAdapter method of getCurrentContentTitle() seems to be overloaded elsewhere in the code.

When creating a notification I create my own Description adapter like so, and I can observe it working as it overloads the Large Icon the description and the content Intent. However, the content title does not get overloaded and instead it uses the media Item's title.

```
private inner class DescriptionAdapter(private val controller: MediaControllerCompat) : PlayerNotificationManager.MediaDescriptionAdapter {

var currentIconUri: Uri? = null
var currentBitmap: Bitmap? = null

override fun getCurrentLargeIcon(
player: Player,
callback: BitmapCallback
): Bitmap? {
val iconUri = controller.metadata.description.iconUri
return if (currentIconUri != iconUri || currentBitmap == null) {

currentIconUri = iconUri
scope.launch {
currentBitmap = iconUri?.let {
resolveUriAsBitmap(it)
}
currentBitmap?.let { callback.onBitmap(it) }
}
null
} else {
currentBitmap
}
}

override fun getCurrentContentTitle(player: Player): CharSequence {
Log.d("Notification2", controller.metadata.description.title.toString() + "asd")
return controller.metadata.description.title.toString() + "asd"
}

override fun createCurrentContentIntent(player: Player): PendingIntent? {
return controller.sessionActivity
}

override fun getCurrentContentText(player: Player): CharSequence? {
return controller.metadata.description.subtitle.toString() + "Hi"
}

private suspend fun resolveUriAsBitmap(uri: Uri): Bitmap? {
return withContext(Dispatchers.IO) {
// Block on downloading artwork.
val request = ImageRequest.Builder(this@MediaPlaybackService)
.data(uri)
.size(144, 144)
.build()
val drawable = this@MediaPlaybackService.imageLoader.execute(request).drawable
return@withContext drawable?.toBitmap()
}
}
}
```

When i disabled my Queue navigator, the content is properly overloaded, hence the asd is shown at the end of the notification title, but if I have it enabled, It fails to show it. This only happens to the title as well for some reason.

```
mediaSessionConnector.setQueueNavigator(object : TimelineQueueNavigator(mediaSession!!) {
override fun getMediaDescription(
player: Player,
windowIndex: Int
): MediaDescriptionCompat {
Log.d("mediaItemAtIndex", windowIndex.toString())
val mediaItemAtIndex = player.getMediaItemAt(windowIndex)

return MediaDescriptionCompat.Builder()
.setTitle("hello")
//.setTitle(mediaItemAtIndex.mediaMetadata.title)
.setDescription(mediaItemAtIndex.mediaMetadata.description)
.setSubtitle(mediaItemAtIndex.mediaMetadata.artist)
.setIconUri(mediaItemAtIndex.mediaMetadata.artworkUri)
.build()
}
})
```

![Screenshot_20220112-182338_VOM](https://user-images.githubusercontent.com/44737462/149249164-ff8f11f0-515d-41e5-a17e-a8a62601589f.jpg)
![Screenshot_20220112-182405_VOM](https://user-images.githubusercontent.com/44737462/149249170-ac2384a5-2fac-45a4-9a23-710aa131e35d.jpg)

As the screen shots show, there is no asd at the end of the content title, but there is a Hi for the content text, and I am completely confused as to why.

- ExoPlayer version number 2.16.1
Android 11
Samsung s20 Plus

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.