Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the role of MediaMetadata.displayTitle in media3? #927

Open
yt8492 opened this issue Dec 28, 2023 · 3 comments
Open

What is the role of MediaMetadata.displayTitle in media3? #927

yt8492 opened this issue Dec 28, 2023 · 3 comments
Assignees
Labels

Comments

@yt8492
Copy link

yt8492 commented Dec 28, 2023

Before media3, Now Playing Card media title refers METADATA_KEY_DISPLAY_TITLE like this.

val mediaMetadataCompatBuilder = MediaMetadataCompat.Builder().apply {
      putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, playable.title)
      putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, playable.subtitle)
      putString(MediaMetadataCompat.METADATA_KEY_ART_URI, playable.artUri)
}

But in media3, when I set displayTitle to MediaMetadata, it seems not working. here is reproducible example.
yt8492@9c959e2

Is this behavior correct? If true, what role is displayTitle in media3?

@yt8492 yt8492 changed the title What is media3 MediaMetadata.displayTitle role? What role is media3 MediaMetadata.displayTitle? Dec 28, 2023
@yt8492 yt8492 changed the title What role is media3 MediaMetadata.displayTitle? What is the role of MediaMetadata.displayTitle in media3? Dec 29, 2023
@marcbaechinger marcbaechinger self-assigned this Dec 29, 2023
@marcbaechinger
Copy link
Contributor

marcbaechinger commented Dec 29, 2023

Thanks for your report.

Media3 is using MediaMetadata.title and converts from and to legacy keys here and here.

So as a Media3 user you can just use MediaMetadata.title. This removes ambiguity for Media3 users and you are still backwards compatible for users of the legacy or platform controller API that need to check both variants.

This behavior seems to be sensible to me. Are you using different values for displayTitle and title in your app and if you do, what is the reason to do so?

@yt8492
Copy link
Author

yt8492 commented Jan 9, 2024

@marcbaechinger
Thank you for the answer.

Are you using different values for displayTitle and title in your app and if you do, what is the reason to do so?

In my case, I only set a value for displayTitle and not for title. There is no particular reason, I simply replaced from ExoPlayer2 to Media3.

ExoPlayer2

val mediaMetadataCompatBuilder = MediaMetadataCompat.Builder().apply {
      putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, playable.title)
      putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, playable.subtitle)
      putString(MediaMetadataCompat.METADATA_KEY_ART_URI, playable.artUri)
}

Media3

val metadata = MediaMetadata.Builder()
        .setDisplayTitle(playable.title)
        .setSubtitle(playable.subtitle)
        .setArtworkUri(playable.artUri)
        .build()

This worked fine most of the cases, but some devices (Xperia, OPPO, etc.) were crashing because they could not get the title from the MediaMetadata.

17:19:20.643  E  java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.os.Bundle.get(java.lang.String)' on a null object reference
--------- beginning of crash
17:19:24.875  E  FATAL EXCEPTION: SysUiBg
                 Process: com.android.systemui, PID: 22574
                 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.media.MediaMetadata.getString(java.lang.String)' on a null object reference
                 	at com.android.systemui.media.MediaDataManager.loadMediaDataInBg(MediaDataManager.kt:500)
                 	at com.android.systemui.media.MediaDataManager.access$loadMediaDataInBg(MediaDataManager.kt:103)
                 	at com.android.systemui.media.MediaDataManager$loadMediaData$1.run(MediaDataManager.kt:308)
                 	at android.os.Handler.handleCallback(Handler.java:938)
                 	at android.os.Handler.dispatchMessage(Handler.java:99)
                 	at android.os.Looper.loopOnce(Looper.java:233)
                 	at android.os.Looper.loop(Looper.java:344)
                 	at android.os.HandlerThread.run(HandlerThread.java:67)

I think this is a bug on the custom os side because MediaDataManager.loadMediaDataInBg in AOSP does a null check, so the NPE should not occur.
I tried setting the value to title as well as displayTitle, and it was improved.

So as a Media3 user you can just use MediaMetadata.title. This removes ambiguity for Media3 users and you are still backwards compatible for users of the legacy or platform controller API that need to check both variants.

I understand. Maybe my fixes in #928 will help in the migration from ExoPlayer2 to Media3, but I think it's not necessary.

@yt8492
Copy link
Author

yt8492 commented Jan 10, 2024

Or, if displayTitle has no role, we can delete displayTitle property from MediaMetadata. It seems more simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants