MediaSessionConnector DefaultMediaMetadataProvider getMetadata NullPointerException
[REQUIRED] Issue description
Hello, I found that using MediaSessionConnector.setPlayer, in some vivo phones, the screen of the mobile phone will appear to go out and enter the unlock interface of the mobile phone.
After investigation, I found that mediaMetadataProvider.getMetadata(player) in MediaSessionConnector.invalidateMediaSessionMetadata returned invalid data.
However, it is found that only some models of the vivo model will have this problem, and other mobile phones can work normally.
public final void invalidateMediaSessionMetadata() {
if (mediaMetadataProvider != null && player != null) {
mediaSession.setMetadata(mediaMetadataProvider.getMetadata(player));
}
}
@Override
public MediaMetadataCompat getMetadata(Player player) {
if (player.getCurrentTimeline().isEmpty()) {
return null;
}
......
}
[REQUIRED] Reproduction steps
Use com.google.android.exoplayer:extension-mediasession:2.9.6 to reproduce this problem in vivo Y55A/Y67, as long as MediaSessionConnector.setPlayer is used
[REQUIRED] Link to test content
[REQUIRED] A full bug report captured from the device
The log currently found is this
04-26 13:16:35.415: I/BufferQueueConsumer(308): --------- beginning of crash
04-26 13:16:35.415: E/AndroidRuntime(11526): FATAL EXCEPTION: VolumeDialogController
04-26 13:16:35.415: E/AndroidRuntime(11526): Process: com.android.systemui, PID: 11526
04-26 13:16:35.415: E/AndroidRuntime(11526): java.lang.NullPointerException: Attempt to invoke virtual method 'android.media.MediaDescription android.media.MediaMetadata.getDescription()' on a null object reference
04-26 13:16:35.415: E/AndroidRuntime(11526): at com.android.systemui.volume.Util.mediaMetadataToString(Util.java:81)
04-26 13:16:35.415: E/AndroidRuntime(11526): at com.android.systemui.volume.MediaSessions$MediaControllerRecord.onMetadataChanged(MediaSessions.java:301)
04-26 13:16:35.415: E/AndroidRuntime(11526): at android.media.session.MediaController$MessageHandler.handleMessage(MediaController.java:1000)
04-26 13:16:35.415: E/AndroidRuntime(11526): at android.os.Handler.dispatchMessage(Handler.java:111)
04-26 13:16:35.415: E/AndroidRuntime(11526): at android.os.Looper.loop(Looper.java:207)
04-26 13:16:35.415: E/AndroidRuntime(11526): at android.os.HandlerThread.run(HandlerThread.java:61)
04-26 13:16:35.415: I/BufferQueueConsumer(308): [unnamed-308-510](this:0x7f89a9f400,id:510,api:0,p:-1,c:308) setConsumerName: unnamed-308-510
[REQUIRED] Version of ExoPlayer being used
com.google.android.exoplayer:exoplayer:2.9.6
com.google.android.exoplayer:exoplayer-ui:2.9.6
com.google.android.exoplayer:extension-mediasession:2.9.6
[REQUIRED] Device(s) and version(s) of Android being used
Operating system: vivo (android6.0)
Phone model: vivo Y67
Operating system: vivo (android6.0.1)
Phone model: vivo Y55A
I have found a solution right now
public class MediaMetadataProvider implements MediaSessionConnector.MediaMetadataProvider {
private MediaSessionConnector.DefaultMediaMetadataProvider defaultMediaMetadataProvider;
public MediaMetadataProvider(
MediaControllerCompat mediaController, @Nullable String metadataExtrasPrefix) {
defaultMediaMetadataProvider =
new MediaSessionConnector.DefaultMediaMetadataProvider(mediaController, metadataExtrasPrefix);
}
@Override
public MediaMetadataCompat getMetadata(Player player) {
MediaMetadataCompat mediaMetadata = defaultMediaMetadataProvider.getMetadata(player);
if (mediaMetadata == null) {
mediaMetadata = new MediaMetadataCompat.Builder().build();
}
return mediaMetadata;
}
}
val mediaSessionConnector = MediaSessionConnector(mediaSession, null,
MediaMetadataProvider(mediaSession.controller, null))
mediaSessionConnector.setPlayer(exoPlayer, mediaPlaybackPreparer)
The strange thing is that our own application did not crash, but the screen of the vivo phone suddenly went out and returned to the unlock interface.
Unlocked into the phone, our app is still there, no crashes
Thanks for reporting!
That's a bug in Android 6 which has been fixed since then. So rather than a device specific issue, this is an issue for devices with Android6 and lower. Thanks for reporting. We will provide a fix to workaround this asap.
The fix will be in 2.10.0.