问题
I am using MediaSession
on Lollipop to control playback. It appears to work because my Android Wear device allows me to control playback, however the phone lock screen isn't showing the image from METADATA_KEY_ALBUM_ART_URI
and the background on Android Wear isn't showing either. I am using my own custom notification (not media style notification). Here is my MediaSession code.
if (mediaSession == null) {
mediaSession = new MediaSession(this, TAG);
mediaSession.setCallback(new MediaSessionCallback());
}
mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder();
metadataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, getMediaTitle());
if (imageURL != null) {
metadataBuilder.putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, imageURL);
}
mediaSession.setMetadata(metadataBuilder.build());
PlaybackState.Builder stateBuilder = new PlaybackState.Builder();
stateBuilder.setActions(PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_REWIND | PlaybackState.ACTION_FAST_FORWARD);
stateBuilder.setState(playStateStatus == Paused ? PlaybackState.STATE_PAUSED : PlaybackState.STATE_PLAYING, PlaybackState.PLAYBACK_POSITION_UNKNOWN, 1.0f);
mediaSession.setPlaybackState(stateBuilder.build());
mediaSession.setActive(true);
Thanks.
回答1:
Looks like the answer is using MediaMetadata.METADATA_KEY_ALBUM_ART
so I'm not sure what the point of METADATA_KEY_ALBUM_ART_URI
is.
metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap);
来源:https://stackoverflow.com/questions/28547024/mediasession-does-not-show-background-on-lock-screen