问题描述
我在Lollipop上使用MediaSession
来控制播放.之所以可以使用它,是因为我的Android Wear设备允许我控制播放,但是手机锁定屏幕上没有显示METADATA_KEY_ALBUM_ART_URI
中的图像,并且Android Wear上的背景也没有显示.我正在使用自己的自定义通知(不是媒体样式通知).这是我的MediaSession代码.
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);
谢谢.
推荐答案
答案似乎是使用MediaMetadata.METADATA_KEY_ALBUM_ART
,所以我不确定METADATA_KEY_ALBUM_ART_URI
的含义是什么.
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,位图);
metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap);
这篇关于MediaSession在锁定屏幕上不显示背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!