我正在为广播电台开发一个简单的音频播放器应用程序。
我已成功创建MediaBrowser
并注册了一个回调来监听playBack
- 或metadata
更改。
var mediaBrowser : MediaBrowserCompat by Delegates.notNull()
mediaBrowser = MediaBrowserCompat(
activity,
ComponentName(activity, MediaPlaybackService::class.java),
object : MediaBrowserCompat.ConnectionCallback() {
override fun onConnected() {
val mediaController = MediaControllerCompat(activity, mediaBrowser.sessionToken)
MediaControllerCompat.setMediaController(activity, mediaController)
mediaController.registerCallback(ControllerCallback)
mediaControllerFunc()
}
},
null
)
object ControllerCallback : MediaControllerCompat.Callback() {
override fun onMetadataChanged(metadata: MediaMetadataCompat) {
//TODO: Never called
}
override fun onPlaybackStateChanged(state: PlaybackStateCompat) {
//Called
}
}
我playback
打电话时收到更改
mediaSession.setPlaybackState(
PlaybackStateCompat.Builder()
.setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE)
.setState(STATE_PLAYING, DEFAULT_PLAYBACK_POSITION, DEFAULT_PLAYBACK_SPEED)
.build()
)
但是元数据更改不是。
即使我打电话
mediaSession.setMetadata(
MediaMetadataCompat.Builder()
.putLong(METADATA_KEY_DURATION, -1)
.putString(METADATA_KEY_TITLE, title)
.putString(METADATA_KEY_ARTIST, artist)
.putBitmap(METADATA_KEY_ALBUM_ART, albumCover)
.putString(METADATA_KEY_ALBUM_ART_URI, albumCoverUrl)
.build()
)
我缺少什么来接收元数据更改?
如果它可以帮助完整的存储库在Github上可用
提前致谢