如何从Cast设备接收状态更新

时间:2014-06-13 16:40:04

标签: android chromecast

我已经开发了与Chromecast集成的Android音频流应用程序。对于接收器,我正在使用Chromecast developer page中描述的样式化媒体接收器。大多数情况下一切正常,但是,我没有在播放期间收到来自Cast设备的onStatusUpdated()调用。当我启动媒体流时,它开始播放并使用IDLE MediaStatus发送状态更新。一旦开始播放,我就会通过PLAYING MediaStatus接收onStatusUpdated()的调用。在此之后,我没有收到任何更新,这意味着我无法使用音频剪辑的当前搜索位置更新我的应用程序UI。

要解决这个问题,我每次运行播放MediaStatus时都会运行Runnable。这是伪代码:

public void onStatusUpdated() {
    ...
    if (mMediaStatus == MediaStatus.PLAYER_STATE_PLAYING) {
        mHandler.postDelayed(mUpdateProgressRunnable, 1000);
        ...

}

mUpdateProgressRunnable = new Runnable() {
    @Override
    public void run() {
        if (mRemoteMediaPlayer != null && mApiClient != null) {
            mRemoteMediaPlayer.requestStatus(mApiClient);
        }
    }
}

这是正确的方法吗?为什么Receiver不能自己发送更新?这似乎工作正常,但我很惊讶,我无法在网上找到有关正确方法的任何信息。

感谢任何帮助!感谢。

2 个答案:

答案 0 :(得分:3)

您需要有一个更新搜索栏的线程。但是,您不需要为视频中的当前位置显式执行requestStatus。你应该打电话

RemoteMediaPlayer.getApproximateStreamPosition

这是由Cast SDK管理的,是跟上接收器上媒体播放进度的有效方法。

答案 1 :(得分:0)

https://github.com/googlecast/CastCompanionLibrary-android/blob/master/src/com/google/sample/castcompanionlibrary/cast/VideoCastManager.java

该CCL类的第851行具有Cast.Listener的实现,可用于对远程播放器上发出的状态事件作出反应。我认为您必须将CCL置于调试模式以获取记录器输出,如“PLAY”期间发生的那样:

D/ccl_MyVideoCastManager( 2765): RemoteMediaPlayer::onStatusUpdated() is reached
D/ccl_MyVideoCastManager( 2765): onRemoteMediaPlayerStatusUpdated() reached 2 0
I/System.out( 2765): status: playing
D/ccl_MyVideoCastManager( 2765): updateMiniControllersVisibility() reached with visibility: true
D/ccl_VideoCastControlle( 2765): onRemoteMediaPlayerStatusUpdated(), status: 2
D/ccl_VideoCastNotificat( 2765): onRemoteMediaPlayerMetadataUpdated() reached with status: 2
D/ccl_MyVideoCastManager( 2765): RemoteMediaPlayer::onStatusUpdated() is reached
D/ccl_MyVideoCastManager( 2765): onRemoteMediaPlayerStatusUpdated() reached 4 0
I/System.out( 2765): status: buffering
D/ccl_MyVideoCastManager( 2765): updateMiniControllersVisibility() reached with visibility: true
D/ccl_VideoCastControlle( 2765): onRemoteMediaPlayerStatusUpdated(), status: 4
D/ccl_VideoCastNotificat( 2765): onRemoteMediaPlayerMetadataUpdated() reached with status: 4
D/ccl_MyVideoCastManager( 2765): RemoteMediaPlayer::onStatusUpdated() is reached
D/ccl_MyVideoCastManager( 2765): onRemoteMediaPlayerStatusUpdated() reached 2 0
I/System.out( 2765): status: playing
D/ccl_MyVideoCastManager( 2765): updateMiniControllersVisibility() reached with visibility: true
D/ccl_VideoCastControlle( 2765): onRemoteMediaPlayerStatusUpdated(), status: 2
D/ccl_VideoCastNotificat( 2765): onRemoteMediaPlayerMetadataUpdated() reached with status: 2
D/ccl_MyVideoCastManager( 2765): RemoteMediaPlayer::onStatusUpdated() is reached
D/ccl_MyVideoCastManager( 2765): onRemoteMediaPlayerStatusUpdated() reached 4 0
I/System.out( 2765): status: buffering
D/ccl_MyVideoCastManager( 2765): updateMiniControllersVisibility() reached with visibility: true
D/ccl_VideoCastControlle( 2765): onRemoteMediaPlayerStatusUpdated(), status: 4
D/ccl_VideoCastNotificat( 2765): onRemoteMediaPlayerMetadataUpdated() reached with status: 4
D/ccl_MyVideoCastManager( 2765): RemoteMediaPlayer::onStatusUpdated() is reached
D/ccl_MyVideoCastManager( 2765): onRemoteMediaPlayerStatusUpdated() reached 2 0
I/System.out( 2765): status: playing
D/ccl_MyVideoCastManager( 2765): updateMiniControllersVisibility() reached with visibility: true
D/ccl_VideoCastControlle( 2765): onRemoteMediaPlayerStatusUpdated(), status: 2
D/ccl_VideoCastNotificat( 2765): onRemoteMediaPlayerMetadataUpdated() reached with status: 2
D/ccl_MyVideoCastManager( 2765): RemoteMediaPlayer::onStatusUpdated() is reached
D/ccl_MyVideoCastManager( 2765): onRemoteMediaPlayerStatusUpdated() reached 4 0
I/System.out( 2765): status: buffering
D/ccl_MyVideoCastManager( 2765): updateMiniControllersVisibility() reached with visibility: true
D/ccl_VideoCastControlle( 2765): onRemoteMediaPlayerStatusUpdated(), status: 4
D/ccl_VideoCastNotificat( 2765): onRemoteMediaPlayerMetadataUpdated() reached with status: 4
D/ccl_MyVideoCastManager( 2765): RemoteMediaPlayer::onStatusUpdated() is reached
D/ccl_MyVideoCastManager( 2765): onRemoteMediaPlayerStatusUpdated() reached 2 0
I/System.out( 2765): status: playing
D/ccl_MyVideoCastManager( 2765): updateMiniControllersVisibility() reached with visibility: true
D/ccl_VideoCastControlle( 2765): onRemoteMediaPlayerStatusUpdated(), status: 2
D/ccl_VideoCastNotificat( 2765): onRemoteMediaPlayerMetadataUpdated() reached with status: 2
D/ccl_MyVideoCastManager( 2765): RemoteMediaPlayer::onStatusUpdated() is reached
D/ccl_MyVideoCastManager( 2765): onRemoteMediaPlayerStatusUpdated() reached 4 0
I/System.out( 2765): status: buffering
D/ccl_MyVideoCastManager( 2765): updateMiniControllersVisibility() reached with visibility: true
D/ccl_VideoCastControlle( 2765): onRemoteMediaPlayerStatusUpdated(), status: 4
D/ccl_VideoCastNotificat( 2765): onRemoteMediaPlayerMetadataUpdated() reached with status: 4
D/dalvikvm(  753): GC_EXPLICIT freed 967K, 7% free 27480K/29484K, paused 1ms+3ms, total 85ms
D/ccl_MyVideoCastManager( 2765): RemoteMediaPlayer::onStatusUpdated() is reached
D/ccl_MyVideoCastManager( 2765): onRemoteMediaPlayerStatusUpdated() reached 2 0

如果你想继续那么去git并获得一个使用CCL的android发送者示例,如'VideoCast'并调试它。您将看到堆栈的重要部分围绕状态更改和此类通知。