Chromecast MediaIntentReceiver 在同一网络中的另一台设备上暂停/播放时未收到任何 intent

Chromecast MediaIntentReceiver not receiving any intent when playback is pause/play from another device in same network

提问人:P Vartak 提问时间:2/2/2023 更新时间:2/18/2023 访问量:117

问:

我们使用 chromecast android sdk 来投射一些视频文件。我们有自己的 play/pause/seek 实现 using (, , )。 此外,我们确实允许 chromecast 在使用 .RemoteMediaClientplay()pause()seek(Long)CastMediaOptions.Builder#setNotificationOptions(NotificationOptions)

为了收听通知控件,我们使用该控件,当我们从完成投射的同一设备的投射通知中控制视频时,该控件完全有效。CastMediaOptions.Builder()#setMediaIntentReceiverClassName(MediaIntentReceiver)

众所周知,Chromecast允许我们控制来自同一wifi网络中所有Android设备的投射媒体。当我们尝试播放/暂停来自同一网络中另一台设备的视频时,不会收到任何内容,并且我们无法更改应用程序内的播放器状态。MediaIntentReceiver

以下是参考代码

选项提供程序


class CastOptionsProvider : OptionsProvider {
    override fun getCastOptions(context: Context): CastOptions {
        val notificationOptions = NotificationOptions.Builder()
            .build()
        val mediaOptions = CastMediaOptions.Builder()
            .setNotificationOptions(notificationOptions)
            .setMediaIntentReceiverClassName(FitbuddMediaIntentReceiver::class.java.name)
            .build()
        return CastOptions.Builder()
            .setReceiverApplicationId(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
            .setCastMediaOptions(mediaOptions)
            .setStopReceiverApplicationWhenEndingSession(true)
            .build()
    }

    override fun getAdditionalSessionProviders(context: Context): List<SessionProvider>? {
        return null
    }
}


MediaIntentReceiver(也在清单中注册)

class FitbuddMediaIntentReceiver : MediaIntentReceiver() {

//this is getting call when playback toggle from same device's notification
//which is casting media but 
//wont get call when playback is toggled from notification from another device 
//inside same network.
override fun onReceiveActionTogglePlayback(currentSession: Session) {
        "CAST -> onReceiveActionTogglePlayback ->".dumpError()
        super.onReceiveActionTogglePlayback(currentSession)
        //send event to active activity
    }
}
Android 投射 广播接收器 Chromecast

评论


答:

0赞 P Vartak 2/18/2023 #1

我们发现,只有在与使用setMediaIntentReceiverClassNameCastMediaOptions.Builder()#setNotificationOptions().

因此,要检查玩家状态,当从其他网络设备更改时,我们使用 which 不提供玩家状态,但提供给定时间段后投射接收器的进度。在我们检查时,我们的 ui 是最新的,具有投射接收器状态。RemoteMediaClient.addProgressListener(RemoteMediaClient.ProgressListener)onProgressUpdatedRemoteMediaClient.playerState