gpt4 book ai didi

android - 在没有 MediaPlayer 的情况下使用 RemoteControlClient

转载 作者:太空狗 更新时间:2023-10-29 14:15:21 25 4
gpt4 key购买 nike

我想将音乐信息从我的播放器广播到锁屏小部件。我现在为了这些目的而存在 RemoteControlClient 类。但是如果我使用自定义引擎来播放音乐呢?如何在锁定屏幕上控制小部件?

最佳答案

我找到了执行此操作的简单方法。

//init remoteControlClient
remoteControlClient = new RemoteControlClient(PendingIntent
.getBroadcast(this, 0, new Intent(Intent.ACTION_MEDIA_BUTTON).setComponent(componentName), 0));
audioManager.registerRemoteControlClient(remoteControlClient);
remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE|RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS|
RemoteControlClient.FLAG_KEY_MEDIA_PAUSE|RemoteControlClient.FLAG_KEY_MEDIA_PLAY);
//put info to the lockscreen
remoteControlClient.editMetadata(true)
.putBitmap(MediaMetadataEditor.BITMAP_KEY_ARTWORK, bitmap)
.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST,audio.getArtist())
.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM,audio.getAlbum())
.putString(MediaMetadataRetriever.METADATA_KEY_TITLE,audio.getTitle()).apply();
//destroy remoteCControlClient
audioManager.unregisterRemoteControlClient(remoteControlClient);

关于android - 在没有 MediaPlayer 的情况下使用 RemoteControlClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22722362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com