如何检测演员完成播放?

时间:2019-06-05 07:53:52

标签: java android chromecast exoplayer2.x

完成播放后如何检测演员表。如果MediaQueueItem中没有转发项目。断开chromecast设备。

检测SessionManagerListener中特定会话类型的事件。

mSessionManagerListener = new SessionManagerListener<CastSession>()
{
    @Override
    public void onSessionStarted(CastSession session, String essionId) {
    castSession.getRemoteMediaClient().queueLoad(mediaItems, 0, 0, null).setResultCallback(new ResultCallback<RemoteMediaClient.MediaChannelResult>() {
        @Override
        public void onResult(@NonNull MediaChannelResult mediaChannelResult) {
            int statusCode = mediaChannelResult.getStatus().getStatusCode();

            if (statusCode == CastStatusCodes.SUCCESS) {
                Log.e(TAG, "statusCode001 :" + statusCode);
            } else {
                Log.e(TAG, "statusCode002 :" + statusCode);
                mRouter.selectRoute(mRouter.getDefaultRoute()); // DisConnect cast
            }

        }
        });
    }
}

当播放器播放媒体时。 Logcat ... statusCode001 0 当完成播放。 Logcat ...没有出现

1 个答案:

答案 0 :(得分:0)

感谢尼尔 并发布Chromecast SDK(Android)-是否可以检查在设备上播放的媒体是否已完成播放? 您的答案,Shivang

这是一个有效的代码。

public int mIdleReason=MediaStatus.IDLE_REASON_NONE;


mSessionManagerListener = new SessionManagerListener<CastSession>()
{
    @Override
    public void onSessionStarted(CastSession session, String sessionId)
    {
            session.getRemoteMediaClient().addListener(mRemoteMediaClientListener);
    }
};

private RemoteMediaClient.Listener mRemoteMediaClientListener = new RemoteMediaClient.Listener() 
{
    @Override
    public void onStatusUpdated()
    {
        int playerStatus = mediaStatus.getPlayerState();

        if (playerStatus == MediaStatus.PLAYER_STATE_PLAYING)
        {
            mIdleReason = MediaStatus.IDLE_REASON_FINISHED;
            Log.e(TAG, "playerStatus PLAYING");
        }
        else if (playerStatus == MediaStatus.PLAYER_STATE_BUFFERING)
        {
            mIdleReason = MediaStatus.IDLE_REASON_FINISHED;
            Log.e(TAG, "playerStatus BUFFERING");
        }
        else if(playerStatus == MediaStatus.PLAYER_STATE_IDLE && mediaStatus.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED && mIdleReason == MediaStatus.IDLE_REASON_FINISHED)
        {
            Log.e(TAG, "statusCode FINISHED");
        }

    }
};

对我来说很好。