Google 指出我需要将品牌、接收器名称和断开连接按钮放在锁定屏幕上。我不知道如何执行此操作,因为 MediaMetadataRetriever 中没有任何用于此数据的字段。目前我正在执行以下操作,我得到的只是插图、标题和控件。
remoteControlClient
.editMetadata(true)
.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, "Title")
.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, bitmap)
.apply();
由于有人请求周围的代码,这里是其中的一些:
private LockscreenManager(Context context) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
ComponentName myEventReceiver = new ComponentName(context, MediaButtonIntentReceiver.class);
audioManager.registerMediaButtonEventReceiver(myEventReceiver);
if (remoteControlClient == null) {
Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
intent.setComponent(myEventReceiver);
remoteControlClient = new RemoteControlClient(PendingIntent.getBroadcast(context, 0, intent, 0));
audioManager.registerRemoteControlClient(remoteControlClient);
}
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
// android built-in lockscreen only supports play/pause/playpause/stop, previous, and next.
remoteControlClient.setTransportControlFlags(
RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE
| RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
| RemoteControlClient.FLAG_KEY_MEDIA_NEXT);
}
public void setMetadata(Film film, Bitmap bitmap) {
remoteControlClient
.editMetadata(true)
.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, film.getDirectorString())
.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, film.getTitle())
.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, film.getDuration()/60)
.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, bitmap)
.apply();
}
public void requestAudioFocus(Context context) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.requestAudioFocus(
new OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {}
},
// Use the music stream.
AudioManager.STREAM_MUSIC,
// Request permanent focus.
AudioManager.AUDIOFOCUS_GAIN);
}
public void removeLockscreenControls() {
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
}
public void setLockscreenPaused() {
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
}
public void setLockscreenPlaying() {
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
}
最佳答案
不幸的是,用户体验指南中的信息并不准确。 RemoteControlClient 目前不支持“停止”按钮(在奇怪的情况下,您可以使其可见,例如将状态设置为“缓冲”,但这不是您想要的),因此您可以跳过“停止”按钮,这将是自然的选择断开连接操作。按钮方面,只能添加显示播放/暂停、下一首、上一首; FF 和 REW 不会出现。最后,在平板电脑上(至少在 Kitkat 上),锁定屏幕会显示应用程序的图标,但在手机上则不会。总而言之,您不需要实现与锁定屏幕的断开连接,也不需要实现品牌(对于手机)。
关于android - 如何将 Chromecast 的品牌、接收器名称和断开连接按钮放入 Android 锁定屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20108935/