org.chromium.chrome.browser.media.remote.RemoteVideoInfo.PlayerState Java Examples

The following examples show how to use org.chromium.chrome.browser.media.remote.RemoteVideoInfo.PlayerState. 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: ExpandedControllerActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    if (mVideoInfo.state == PlayerState.FINISHED) finish();
    if (mMediaRouteController == null) return;

    // Lifetime of the media element is bound to that of the {@link MediaStateListener}
    // of the {@link MediaRouteController}.
    RecordCastAction.recordFullscreenControlsShown(
            mMediaRouteController.getMediaStateListener() != null);

    mMediaRouteController.prepareMediaRoute();

    ImageView iv = (ImageView) findViewById(R.id.cast_background_image);
    if (iv == null) return;
    Bitmap posterBitmap = mMediaRouteController.getPoster();
    if (posterBitmap != null) iv.setImageBitmap(posterBitmap);
    iv.setImageAlpha(POSTER_IMAGE_ALPHA);
}
 
Example #2
Source File: CastNotificationControl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onPlaybackStateChanged(PlayerState newState) {
    if (!mIsShowing
            && (newState == PlayerState.PLAYING || newState == PlayerState.LOADING
                    || newState == PlayerState.PAUSED)) {
        show(newState);
        return;
    }

    if (mState == newState
            || mState == PlayerState.PAUSED && newState == PlayerState.LOADING && mIsShowing) {
        return;
    }

    mState = newState;
    updateNotification();
}
 
Example #3
Source File: CastNotificationControl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void updateNotification() {
    // Nothing shown yet, nothing to update.
    if (mNotificationBuilder == null) return;

    mNotificationBuilder.setMetadata(new MediaMetadata(mTitle, "", ""));
    if (mState == PlayerState.PAUSED || mState == PlayerState.PLAYING) {
        mNotificationBuilder.setPaused(mState != PlayerState.PLAYING);
        mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP
                | MediaNotificationInfo.ACTION_PLAY_PAUSE);
        MediaNotificationManager.show(mContext, mNotificationBuilder.build());
    } else if (mState == PlayerState.LOADING) {
        mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP);
        MediaNotificationManager.show(mContext, mNotificationBuilder.build());
    } else {
        hide();
    }
}
 
Example #4
Source File: CastNotificationControl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
public void show(PlayerState initialState) {
    mMediaRouteController.addUiListener(this);
    // TODO(aberent): investigate why this is necessary, and whether we are handling
    // it correctly. Also add code to restore it when Chrome is resumed.
    mAudioManager.requestAudioFocus(this, AudioManager.USE_DEFAULT_STREAM_TYPE,
            AudioManager.AUDIOFOCUS_GAIN);
    Intent contentIntent = new Intent(mContext, ExpandedControllerActivity.class);
    contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME,
            MediaNotificationUma.SOURCE_MEDIA_FLING);
    mNotificationBuilder = new MediaNotificationInfo.Builder()
            .setPaused(false)
            .setPrivate(false)
            .setIcon(R.drawable.ic_notification_media_route)
            .setContentIntent(contentIntent)
            .setLargeIcon(mMediaRouteController.getPoster())
            .setDefaultLargeIcon(R.drawable.cast_playing_square)
            .setId(R.id.remote_notification)
            .setListener(this);
    mState = initialState;
    updateNotification();
    mIsShowing = true;
}
 
Example #5
Source File: ExpandedControllerActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    if (mVideoInfo.state == PlayerState.FINISHED) finish();
    if (mMediaRouteController == null) return;

    // Lifetime of the media element is bound to that of the {@link MediaStateListener}
    // of the {@link MediaRouteController}.
    RecordCastAction.recordFullscreenControlsShown(
            mMediaRouteController.getMediaStateListener() != null);

    mMediaRouteController.prepareMediaRoute();

    ImageView iv = (ImageView) findViewById(R.id.cast_background_image);
    if (iv == null) return;
    Bitmap posterBitmap = mMediaRouteController.getPoster();
    if (posterBitmap != null) iv.setImageBitmap(posterBitmap);
    iv.setImageAlpha(POSTER_IMAGE_ALPHA);
}
 
Example #6
Source File: CastNotificationControl.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onPlaybackStateChanged(PlayerState newState) {
    if (!mIsShowing
            && (newState == PlayerState.PLAYING || newState == PlayerState.LOADING
                    || newState == PlayerState.PAUSED)) {
        show(newState);
        return;
    }

    if (mState == newState
            || mState == PlayerState.PAUSED && newState == PlayerState.LOADING && mIsShowing) {
        return;
    }

    mState = newState;
    updateNotification();
}
 
Example #7
Source File: CastNotificationControl.java    From delion with Apache License 2.0 6 votes vote down vote up
private void updateNotification() {
    // Nothing shown yet, nothing to update.
    if (mNotificationBuilder == null) return;

    mNotificationBuilder.setMetadata(new MediaMetadata(mTitle, "", ""));
    if (mState == PlayerState.PAUSED || mState == PlayerState.PLAYING) {
        mNotificationBuilder.setPaused(mState != PlayerState.PLAYING);
        mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP
                | MediaNotificationInfo.ACTION_PLAY_PAUSE);
        MediaNotificationManager.show(mContext, mNotificationBuilder.build());
    } else if (mState == PlayerState.LOADING) {
        mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP);
        MediaNotificationManager.show(mContext, mNotificationBuilder.build());
    } else {
        hide();
    }
}
 
Example #8
Source File: CastNotificationControl.java    From delion with Apache License 2.0 6 votes vote down vote up
public void show(PlayerState initialState) {
    mMediaRouteController.addUiListener(this);
    // TODO(aberent): investigate why this is necessary, and whether we are handling
    // it correctly. Also add code to restore it when Chrome is resumed.
    mAudioManager.requestAudioFocus(this, AudioManager.USE_DEFAULT_STREAM_TYPE,
            AudioManager.AUDIOFOCUS_GAIN);
    Intent contentIntent = new Intent(mContext, ExpandedControllerActivity.class);
    contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME,
            MediaNotificationUma.SOURCE_MEDIA_FLING);
    mNotificationBuilder = new MediaNotificationInfo.Builder()
            .setPaused(false)
            .setPrivate(false)
            .setIcon(R.drawable.ic_notification_media_route)
            .setContentIntent(contentIntent)
            .setLargeIcon(mMediaRouteController.getPoster())
            .setDefaultLargeIcon(R.drawable.cast_playing_square)
            .setId(R.id.remote_notification)
            .setListener(this);
    mState = initialState;
    updateNotification();
    mIsShowing = true;
}
 
Example #9
Source File: CastNotificationControl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public void show(PlayerState initialState) {
    mMediaRouteController.addUiListener(this);
    // TODO(aberent): investigate why this is necessary, and whether we are handling
    // it correctly. Also add code to restore it when Chrome is resumed.
    mAudioManager.requestAudioFocus(this, AudioManager.USE_DEFAULT_STREAM_TYPE,
            AudioManager.AUDIOFOCUS_GAIN);
    Intent contentIntent = new Intent(mContext, ExpandedControllerActivity.class);
    contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME,
            MediaNotificationUma.SOURCE_MEDIA_FLING);
    mNotificationBuilder = new MediaNotificationInfo.Builder()
            .setPaused(false)
            .setPrivate(false)
            .setNotificationSmallIcon(R.drawable.ic_notification_media_route)
            .setContentIntent(contentIntent)
            .setDefaultNotificationLargeIcon(R.drawable.cast_playing_square)
            .setId(R.id.remote_notification)
            .setListener(this);

    updateNotificationBuilderIfPosterIsGoodEnough();
    mState = initialState;

    updateNotification();
    mIsShowing = true;
}
 
Example #10
Source File: CastNotificationControl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void updateNotification() {
    // Nothing shown yet, nothing to update.
    if (mNotificationBuilder == null) return;

    mNotificationBuilder.setMetadata(new MediaMetadata(mTitle, "", ""));
    if (mTabOrigin != null) mNotificationBuilder.setOrigin(mTabOrigin);

    if (mState == PlayerState.PAUSED || mState == PlayerState.PLAYING) {
        mNotificationBuilder.setPaused(mState != PlayerState.PLAYING);
        mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP
                | MediaNotificationInfo.ACTION_PLAY_PAUSE);
        MediaNotificationManager.show(mNotificationBuilder.build());
    } else if (mState == PlayerState.LOADING) {
        mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP);
        MediaNotificationManager.show(mNotificationBuilder.build());
    } else {
        hide();
    }
}
 
Example #11
Source File: CastNotificationControl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onPlaybackStateChanged(PlayerState newState) {
    if (!mIsShowing
            && (newState == PlayerState.PLAYING || newState == PlayerState.LOADING
                    || newState == PlayerState.PAUSED)) {
        show(newState);
        return;
    }

    if (mState == newState
            || mState == PlayerState.PAUSED && newState == PlayerState.LOADING && mIsShowing) {
        return;
    }

    mState = newState;
    updateNotification();
}
 
Example #12
Source File: ExpandedControllerActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    if (mVideoInfo.state == PlayerState.FINISHED) finish();
    if (mMediaRouteController == null) return;

    // Lifetime of the media element is bound to that of the {@link MediaStateListener}
    // of the {@link MediaRouteController}.
    RecordCastAction.recordFullscreenControlsShown(
            mMediaRouteController.getMediaStateListener() != null);

    mMediaRouteController.prepareMediaRoute();

    ImageView iv = (ImageView) findViewById(R.id.cast_background_image);
    if (iv == null) return;
    Bitmap posterBitmap = mMediaRouteController.getPoster();
    if (posterBitmap != null) iv.setImageBitmap(posterBitmap);
    iv.setImageAlpha(POSTER_IMAGE_ALPHA);
}
 
Example #13
Source File: AbstractMediaRouteController.java    From delion with Apache License 2.0 5 votes vote down vote up
protected void setDisplayedPlayerState(PlayerState state) {
    mDisplayedPlayerState = state;
    for (UiListener listener : mUiListeners) {
        listener.onPlaybackStateChanged(mDisplayedPlayerState);
    }
    if (mMediaStateListener != null) {
        mMediaStateListener.onPlaybackStateChanged(mDisplayedPlayerState);
    }
}
 
Example #14
Source File: AbstractMediaRouteController.java    From delion with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void setPlayerStateForMediaItemState(int state) {
    PlayerState playerState = PlayerState.STOPPED;
    switch (state) {
        case MediaItemStatus.PLAYBACK_STATE_BUFFERING:
            playerState = PlayerState.LOADING;
            break;
        case MediaItemStatus.PLAYBACK_STATE_CANCELED:
            playerState = PlayerState.FINISHED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_ERROR:
            playerState = PlayerState.ERROR;
            break;
        case MediaItemStatus.PLAYBACK_STATE_FINISHED:
            playerState = PlayerState.FINISHED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_INVALIDATED:
            playerState = PlayerState.INVALIDATED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_PAUSED:
            if (isAtEndOfVideo(getPosition(), getDuration())) {
                playerState = PlayerState.FINISHED;
            } else {
                playerState = PlayerState.PAUSED;
            }
            break;
        case MediaItemStatus.PLAYBACK_STATE_PENDING:
            playerState = PlayerState.PAUSED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_PLAYING:
            playerState = PlayerState.PLAYING;
            break;
        default:
            break;
    }

    mRemotePlayerState = playerState;
}
 
Example #15
Source File: RemoteMediaPlayerBridge.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onPlaybackStateChanged(PlayerState newState) {
    if (mNativeRemoteMediaPlayerBridge == 0) return;
    if (newState == PlayerState.FINISHED || newState == PlayerState.INVALIDATED) {
        nativeOnPlaybackFinished(mNativeRemoteMediaPlayerBridge);
    } else if (newState == PlayerState.PLAYING) {
        nativeOnPlaying(mNativeRemoteMediaPlayerBridge);
    } else if (newState == PlayerState.PAUSED) {
        mPauseRequested = false;
        nativeOnPaused(mNativeRemoteMediaPlayerBridge);
    }
}
 
Example #16
Source File: ExpandedControllerActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();
    if ((keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_UP)
            || mVideoInfo.state == PlayerState.FINISHED) {
        return super.dispatchKeyEvent(event);
    }

    return handleVolumeKeyEvent(mMediaRouteController, event);
}
 
Example #17
Source File: ExpandedControllerActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onPlaybackStateChanged(PlayerState newState) {
    RemoteVideoInfo videoInfo = new RemoteVideoInfo(mVideoInfo);
    videoInfo.state = newState;
    setVideoInfo(videoInfo);

    scheduleProgressUpdate();

    if (newState == PlayerState.FINISHED || newState == PlayerState.INVALIDATED) {
        // If we are switching to a finished state, stop the notifications.
        finish();
    }
}
 
Example #18
Source File: AbstractMediaRouteController.java    From delion with Apache License 2.0 5 votes vote down vote up
protected void updateState(int state) {
    Log.d(TAG, "updateState oldState: %s player state: %s", mRemotePlayerState, state);

    PlayerState oldState = mRemotePlayerState;
    setPlayerStateForMediaItemState(state);

    Log.d(TAG, "updateState newState: %s", mRemotePlayerState);

    if (oldState != mRemotePlayerState) {
        setDisplayedPlayerState(mRemotePlayerState);

        switch (mRemotePlayerState) {
            case PLAYING:
                onCasting();
                break;
            case PAUSED:
                onCasting();
                break;
            case FINISHED:
                release();
                break;
            case INVALIDATED:
                clearItemState();
                break;
            case ERROR:
                sendErrorToListeners(CastMediaControlIntent.ERROR_CODE_REQUEST_FAILED);
                release();
                break;
            default:
                break;
        }
    }
}
 
Example #19
Source File: DefaultMediaRouteController.java    From delion with Apache License 2.0 5 votes vote down vote up
private void processSessionStatusBundle(Bundle statusBundle) {
    MediaSessionStatus status = MediaSessionStatus.fromBundle(
            statusBundle.getBundle(MediaControlIntent.EXTRA_SESSION_STATUS));
    int sessionState = status.getSessionState();

    // If no change do nothing
    if (sessionState == mSessionState) return;
    mSessionState = sessionState;

    switch (sessionState) {
        case MediaSessionStatus.SESSION_STATE_ACTIVE:
            if (mLocalVideoUri != null) {
                startPlayback(mPreferredTitle, mStartPositionMillis);
            }
            break;

        case MediaSessionStatus.SESSION_STATE_ENDED:
        case MediaSessionStatus.SESSION_STATE_INVALIDATED:
            for (UiListener listener : getUiListeners()) {
                listener.onPlaybackStateChanged(PlayerState.INVALIDATED);
            }
            if (getMediaStateListener() != null) {
                getMediaStateListener().onPlaybackStateChanged(PlayerState.INVALIDATED);
            }
            // Record the remaining time UMA first, otherwise the playback state will be cleared
            // in release().
            recordRemainingTimeUMA();
            // Set the current session id to null so we don't send the stop intent.
            mCurrentSessionId = null;
            release();
            break;

        default:
            break;
    }
}
 
Example #20
Source File: ExpandedControllerActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();
    if ((keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_UP)
            || mVideoInfo.state == PlayerState.FINISHED) {
        return super.dispatchKeyEvent(event);
    }

    return handleVolumeKeyEvent(mMediaRouteController, event);
}
 
Example #21
Source File: AbstractMediaRouteController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void setPlayerStateForMediaItemState(int state) {
    PlayerState playerState = PlayerState.STOPPED;
    switch (state) {
        case MediaItemStatus.PLAYBACK_STATE_BUFFERING:
            playerState = PlayerState.LOADING;
            break;
        case MediaItemStatus.PLAYBACK_STATE_CANCELED:
            playerState = PlayerState.FINISHED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_ERROR:
            playerState = PlayerState.ERROR;
            break;
        case MediaItemStatus.PLAYBACK_STATE_FINISHED:
            playerState = PlayerState.FINISHED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_INVALIDATED:
            playerState = PlayerState.INVALIDATED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_PAUSED:
            if (isAtEndOfVideo(getPosition(), getDuration())) {
                playerState = PlayerState.FINISHED;
            } else {
                playerState = PlayerState.PAUSED;
            }
            break;
        case MediaItemStatus.PLAYBACK_STATE_PENDING:
            playerState = PlayerState.PAUSED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_PLAYING:
            playerState = PlayerState.PLAYING;
            break;
        default:
            break;
    }

    mRemotePlayerState = playerState;
}
 
Example #22
Source File: AbstractMediaRouteController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
protected void updateState(int state) {
    Log.d(TAG, "updateState oldState: %s player state: %s", mRemotePlayerState, state);

    PlayerState oldState = mRemotePlayerState;
    setPlayerStateForMediaItemState(state);

    Log.d(TAG, "updateState newState: %s", mRemotePlayerState);

    if (oldState != mRemotePlayerState) {
        setDisplayedPlayerState(mRemotePlayerState);

        switch (mRemotePlayerState) {
            case PLAYING:
                onCasting();
                break;
            case PAUSED:
                onCasting();
                break;
            case FINISHED:
                release();
                break;
            case INVALIDATED:
                clearItemState();
                break;
            case ERROR:
                sendErrorToListeners(CastMediaControlIntent.ERROR_CODE_REQUEST_FAILED);
                release();
                break;
            default:
                break;
        }
    }
}
 
Example #23
Source File: AbstractMediaRouteController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
protected void setDisplayedPlayerState(PlayerState state) {
    mDisplayedPlayerState = state;
    for (UiListener listener : mUiListeners) {
        listener.onPlaybackStateChanged(mDisplayedPlayerState);
    }
    if (mMediaStateListener != null) {
        mMediaStateListener.onPlaybackStateChanged(mDisplayedPlayerState);
    }
}
 
Example #24
Source File: AbstractMediaRouteController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
protected void setDisplayedPlayerState(PlayerState state) {
    mDisplayedPlayerState = state;
    for (UiListener listener : mUiListeners) {
        listener.onPlaybackStateChanged(mDisplayedPlayerState);
    }
    if (mMediaStateListener != null) {
        mMediaStateListener.onPlaybackStateChanged(mDisplayedPlayerState);
    }
}
 
Example #25
Source File: DefaultMediaRouteController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void processSessionStatusBundle(Bundle statusBundle) {
    MediaSessionStatus status = MediaSessionStatus.fromBundle(
            statusBundle.getBundle(MediaControlIntent.EXTRA_SESSION_STATUS));
    int sessionState = status.getSessionState();

    // If no change do nothing
    if (sessionState == mSessionState) return;
    mSessionState = sessionState;

    switch (sessionState) {
        case MediaSessionStatus.SESSION_STATE_ACTIVE:
            if (mLocalVideoUri != null) {
                startPlayback(mPreferredTitle, mStartPositionMillis);
            }
            break;

        case MediaSessionStatus.SESSION_STATE_ENDED:
        case MediaSessionStatus.SESSION_STATE_INVALIDATED:
            for (UiListener listener : getUiListeners()) {
                listener.onPlaybackStateChanged(PlayerState.INVALIDATED);
            }
            if (getMediaStateListener() != null) {
                getMediaStateListener().onPlaybackStateChanged(PlayerState.INVALIDATED);
            }
            // Record the remaining time UMA first, otherwise the playback state will be cleared
            // in release().
            recordRemainingTimeUMA();
            // Set the current session id to null so we don't send the stop intent.
            mCurrentSessionId = null;
            release();
            break;

        default:
            break;
    }
}
 
Example #26
Source File: ExpandedControllerActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();
    if ((keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_UP)
            || mVideoInfo.state == PlayerState.FINISHED) {
        return super.dispatchKeyEvent(event);
    }

    return handleVolumeKeyEvent(mMediaRouteController, event);
}
 
Example #27
Source File: ExpandedControllerActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onPlaybackStateChanged(PlayerState newState) {
    RemoteVideoInfo videoInfo = new RemoteVideoInfo(mVideoInfo);
    videoInfo.state = newState;
    setVideoInfo(videoInfo);

    scheduleProgressUpdate();

    if (newState == PlayerState.FINISHED || newState == PlayerState.INVALIDATED) {
        // If we are switching to a finished state, stop the notifications.
        finish();
    }
}
 
Example #28
Source File: AbstractMediaRouteController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void setPlayerStateForMediaItemState(int state) {
    PlayerState playerState = PlayerState.STOPPED;
    switch (state) {
        case MediaItemStatus.PLAYBACK_STATE_BUFFERING:
            playerState = PlayerState.LOADING;
            break;
        case MediaItemStatus.PLAYBACK_STATE_CANCELED:
            playerState = PlayerState.FINISHED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_ERROR:
            playerState = PlayerState.ERROR;
            break;
        case MediaItemStatus.PLAYBACK_STATE_FINISHED:
            playerState = PlayerState.FINISHED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_INVALIDATED:
            playerState = PlayerState.INVALIDATED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_PAUSED:
            if (isAtEndOfVideo(getPosition(), getDuration())) {
                playerState = PlayerState.FINISHED;
            } else {
                playerState = PlayerState.PAUSED;
            }
            break;
        case MediaItemStatus.PLAYBACK_STATE_PENDING:
            playerState = PlayerState.PAUSED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_PLAYING:
            playerState = PlayerState.PLAYING;
            break;
        default:
            break;
    }

    mRemotePlayerState = playerState;
}
 
Example #29
Source File: AbstractMediaRouteController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
protected void updateState(int state) {
    Log.d(TAG, "updateState oldState: %s player state: %s", mRemotePlayerState, state);

    PlayerState oldState = mRemotePlayerState;
    setPlayerStateForMediaItemState(state);

    Log.d(TAG, "updateState newState: %s", mRemotePlayerState);

    if (oldState != mRemotePlayerState) {
        setDisplayedPlayerState(mRemotePlayerState);

        switch (mRemotePlayerState) {
            case PLAYING:
                onCasting();
                break;
            case PAUSED:
                onCasting();
                break;
            case FINISHED:
                release();
                break;
            case INVALIDATED:
                clearItemState();
                break;
            case ERROR:
                sendErrorToListeners(CastMediaControlIntent.ERROR_CODE_REQUEST_FAILED);
                release();
                break;
            default:
                break;
        }
    }
}
 
Example #30
Source File: RemoteMediaPlayerBridge.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onPlaybackStateChanged(PlayerState newState) {
    if (mNativeRemoteMediaPlayerBridge == 0) return;
    if (newState == PlayerState.FINISHED || newState == PlayerState.INVALIDATED) {
        nativeOnPlaybackFinished(mNativeRemoteMediaPlayerBridge);
    } else if (newState == PlayerState.PLAYING) {
        nativeOnPlaying(mNativeRemoteMediaPlayerBridge);
    } else if (newState == PlayerState.PAUSED) {
        mPauseRequested = false;
        nativeOnPaused(mNativeRemoteMediaPlayerBridge);
    }
}