Java Code Examples for com.google.android.gms.cast.framework.media.RemoteMediaClient#getPlayerState()

The following examples show how to use com.google.android.gms.cast.framework.media.RemoteMediaClient#getPlayerState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueueListAdapter.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
private void updatePlayPauseButtonImageResource(ImageButton button) {
    CastSession castSession = CastContext.getSharedInstance(mAppContext)
            .getSessionManager().getCurrentCastSession();
    RemoteMediaClient remoteMediaClient =
            (castSession == null) ? null : castSession.getRemoteMediaClient();
    if (remoteMediaClient == null) {
        button.setVisibility(View.GONE);
        return;
    }
    int status = remoteMediaClient.getPlayerState();
    switch (status) {
        case MediaStatus.PLAYER_STATE_PLAYING:
            button.setImageResource(PAUSE_RESOURCE);
            break;
        case MediaStatus.PLAYER_STATE_PAUSED:
            button.setImageResource(PLAY_RESOURCE);
            break;
        default:
            button.setVisibility(View.GONE);
    }
}
 
Example 2
Source File: GoogleCastDelegate.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onStatusUpdated() {
    super.onStatusUpdated();
    if (sessionListener != null && castSession != null) {
        final RemoteMediaClient remoteMediaPlayer = castSession.getRemoteMediaClient();
        if (remoteMediaPlayer != null) {
            if (remoteMediaPlayer.getPlayerState() == MediaStatus.PLAYER_STATE_IDLE &&
                    remoteMediaPlayer.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED) {
                sessionListener.onVideoComplete();
            } else if (remoteMediaPlayer.getPlayerState() == MediaStatus.PLAYER_STATE_PLAYING) {
                sessionListener.onVideoPlaying();
            }
        }
    }
}