Java Code Examples for com.google.android.exoplayer2.Player#STATE_IDLE
The following examples show how to use
com.google.android.exoplayer2.Player#STATE_IDLE .
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: VideoPlayer.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
@Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { switch(playbackState) { case Player.STATE_IDLE: case Player.STATE_BUFFERING: case Player.STATE_ENDED: window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); break; case Player.STATE_READY: if (playWhenReady) { window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } else { window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } notifyPlayerReady(); break; default: break; } }
Example 2
Source File: PlaybackStatsListener.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * Creates a tracker for playback stats. * * @param keepHistory Whether to keep a full history of events. * @param startTime The {@link EventTime} at which the playback stats start. */ public PlaybackStatsTracker(boolean keepHistory, EventTime startTime) { this.keepHistory = keepHistory; playbackStateDurationsMs = new long[PlaybackStats.PLAYBACK_STATE_COUNT]; playbackStateHistory = keepHistory ? new ArrayList<>() : Collections.emptyList(); mediaTimeHistory = keepHistory ? new ArrayList<>() : Collections.emptyList(); videoFormatHistory = keepHistory ? new ArrayList<>() : Collections.emptyList(); audioFormatHistory = keepHistory ? new ArrayList<>() : Collections.emptyList(); fatalErrorHistory = keepHistory ? new ArrayList<>() : Collections.emptyList(); nonFatalErrorHistory = keepHistory ? new ArrayList<>() : Collections.emptyList(); currentPlaybackState = PlaybackStats.PLAYBACK_STATE_NOT_STARTED; currentPlaybackStateStartTimeMs = startTime.realtimeMs; playerPlaybackState = Player.STATE_IDLE; firstReportedTimeMs = C.TIME_UNSET; maxRebufferTimeMs = C.TIME_UNSET; isAd = startTime.mediaPeriodId != null && startTime.mediaPeriodId.isAd(); initialAudioFormatBitrate = C.LENGTH_UNSET; initialVideoFormatBitrate = C.LENGTH_UNSET; initialVideoFormatHeight = C.LENGTH_UNSET; currentPlaybackSpeed = 1f; }
Example 3
Source File: ExoPlayerImpl.java From MediaSDK with Apache License 2.0 | 6 votes |
@Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { LogUtils.d("onPlayerStateChanged playWhenReady="+playWhenReady+", playbackState="+playbackState); switch(playbackState) { case Player.STATE_BUFFERING: break; case Player.STATE_IDLE: break; case Player.STATE_READY: if (mPrepareState == PREPARING_STATE) { notifyOnPrepared(); mPrepareState = PREPARED_STATE; } break; case Player.STATE_ENDED: break; default: break; } }
Example 4
Source File: LocalPlayback.java From klingar with Apache License 2.0 | 6 votes |
@Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { Timber.d("onPlayerStateChanged %s playWhenReady %s", getExoPlayerState(playbackState), playWhenReady); switch (playbackState) { case Player.STATE_IDLE: case Player.STATE_BUFFERING: case Player.STATE_READY: if (callback != null) { callback.onPlaybackStatusChanged(); } break; case Player.STATE_ENDED: if (callback != null) { callback.onCompletion(); } break; default: break; } }
Example 5
Source File: ExoVideoPlaybackControlView.java From ExoVideoView with Apache License 2.0 | 6 votes |
@Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playbackState != Player.STATE_IDLE && centerError != null && centerError.getVisibility() == VISIBLE) { centerError.setVisibility(GONE); } if (playbackState == Player.STATE_IDLE || playbackState == Player.STATE_BUFFERING) { removeCallbacks(hideAction); showUtilHideCalled(); showLoading(true); } else if (playbackState == Player.STATE_READY && player.getPlayWhenReady() || playbackState == Player.STATE_ENDED) { showLoading(false); hide(); } updatePlayPauseButton(); updateProgress(); }
Example 6
Source File: CustomizePlayerView.java From bcm-android with GNU General Public License v3.0 | 6 votes |
private void updateErrorMessage() { if (errorMessageView != null) { if (customErrorMessage != null) { errorMessageView.setText(customErrorMessage); errorMessageView.setVisibility(View.VISIBLE); return; } ExoPlaybackException error = null; if (player != null && player.getPlaybackState() == Player.STATE_IDLE && errorMessageProvider != null) { error = player.getPlaybackError(); } if (error != null) { CharSequence errorMessage = errorMessageProvider.getErrorMessage(error).second; errorMessageView.setText(errorMessage); errorMessageView.setVisibility(View.VISIBLE); } else { errorMessageView.setVisibility(View.GONE); } } }
Example 7
Source File: AudioFocusManager.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Called by the player as part of {@link ExoPlayer#setPlayWhenReady(boolean)}. * * @param playWhenReady The desired value of playWhenReady. * @param playerState The current state of the player. * @return A {@link PlayerCommand} to execute on the player. */ @PlayerCommand public int handleSetPlayWhenReady(boolean playWhenReady, int playerState) { if (!playWhenReady) { abandonAudioFocus(); return PLAYER_COMMAND_DO_NOT_PLAY; } return playerState == Player.STATE_IDLE ? handleIdle(playWhenReady) : requestAudioFocus(); }
Example 8
Source File: ExoMediaPlayer.java From DKVideoPlayer with Apache License 2.0 | 5 votes |
@Override public void reset() { if (mInternalPlayer != null) { mInternalPlayer.stop(true); mInternalPlayer.setVideoSurface(null); mIsPreparing = false; mIsBuffering = false; mLastReportedPlaybackState = Player.STATE_IDLE; mLastReportedPlayWhenReady = false; } }
Example 9
Source File: ExoMediaPlayer.java From PlayerBase with Apache License 2.0 | 5 votes |
@Override public boolean isPlaying() { if (mInternalPlayer == null) return false; int state = mInternalPlayer.getPlaybackState(); switch (state) { case Player.STATE_BUFFERING: case Player.STATE_READY: return mInternalPlayer.getPlayWhenReady(); case Player.STATE_IDLE: case Player.STATE_ENDED: default: return false; } }
Example 10
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 5 votes |
private void reportPlayerState() { boolean playWhenReady = player.getPlayWhenReady(); int playbackState = getPlaybackState(); int newState = stateStore.getState(playWhenReady, playbackState); if (newState != stateStore.getMostRecentState()) { stateStore.setMostRecentState(playWhenReady, playbackState); //Makes sure the buffering notifications are sent if (newState == Player.STATE_READY) { setBufferRepeaterStarted(true); } else if (newState == Player.STATE_IDLE || newState == Player.STATE_ENDED) { setBufferRepeaterStarted(false); } //Because the playWhenReady isn't a state in itself, rather a flag to a state we will ignore informing of // see events when that is the only change. Additionally, on some devices we get states ordered as // [seeking, ready, buffering, ready] while on others we get [seeking, buffering, ready] boolean informSeekCompletion = stateStore.matchesHistory(new int[]{StateStore.STATE_SEEKING, Player.STATE_BUFFERING, Player.STATE_READY}, true); informSeekCompletion |= stateStore.matchesHistory(new int[]{Player.STATE_BUFFERING, StateStore.STATE_SEEKING, Player.STATE_READY}, true); informSeekCompletion |= stateStore.matchesHistory(new int[]{StateStore.STATE_SEEKING, Player.STATE_READY, Player.STATE_BUFFERING, Player.STATE_READY}, true); for (ExoPlayerListener listener : listeners) { listener.onStateChanged(playWhenReady, playbackState); if (informSeekCompletion) { listener.onSeekComplete(); } } } }
Example 11
Source File: EventLogger.java From Telegram with GNU General Public License v2.0 | 5 votes |
private static String getStateString(int state) { switch (state) { case Player.STATE_BUFFERING: return "BUFFERING"; case Player.STATE_ENDED: return "ENDED"; case Player.STATE_IDLE: return "IDLE"; case Player.STATE_READY: return "READY"; default: return "?"; } }
Example 12
Source File: CustomExoPlayerView.java From leafpicrevived with GNU General Public License v3.0 | 5 votes |
private boolean shouldShowControllerIndefinitely() { if (player == null) { return true; } int playbackState = player.getPlaybackState(); return (playbackState == Player.STATE_IDLE || playbackState == Player.STATE_ENDED || !player.getPlayWhenReady()); }
Example 13
Source File: CustomPlayBackController.java From leafpicrevived with GNU General Public License v3.0 | 5 votes |
private void updateProgress() { if (!isVisible() || !isAttachedToWindow) return; long duration = player == null ? 0 : player.getDuration(); long position = player == null ? 0 : player.getCurrentPosition(); time.setText(stringForTime(duration)); if (!dragging) { timeCurrent.setText(stringForTime(position)); } if (!dragging) { progressBar.setProgress(progressBarValue(position)); } long bufferedPosition = player == null ? 0 : player.getBufferedPosition(); progressBar.setSecondaryProgress(progressBarValue(bufferedPosition)); // Remove scheduled updates. removeCallbacks(updateProgressAction); // Schedule an update if necessary. int playbackState = player == null ? Player.STATE_IDLE : player.getPlaybackState(); if (playbackState != Player.STATE_IDLE && playbackState != Player.STATE_ENDED) { long delayMs; if (player.getPlayWhenReady() && playbackState == Player.STATE_READY) { delayMs = 1000 - (position % 1000); if (delayMs < 200) { delayMs += 1000; } } else { delayMs = 1000; } postDelayed(updateProgressAction, delayMs); } }
Example 14
Source File: AudioFocusManager.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Called by the player as part of {@link ExoPlayer#setPlayWhenReady(boolean)}. * * @param playWhenReady The desired value of playWhenReady. * @param playerState The current state of the player. * @return A {@link PlayerCommand} to execute on the player. */ @PlayerCommand public int handleSetPlayWhenReady(boolean playWhenReady, int playerState) { if (!playWhenReady) { abandonAudioFocus(); return PLAYER_COMMAND_DO_NOT_PLAY; } return playerState == Player.STATE_IDLE ? handleIdle(playWhenReady) : requestAudioFocus(); }
Example 15
Source File: EventLogger.java From MediaSDK with Apache License 2.0 | 5 votes |
private static String getStateString(int state) { switch (state) { case Player.STATE_BUFFERING: return "BUFFERING"; case Player.STATE_ENDED: return "ENDED"; case Player.STATE_IDLE: return "IDLE"; case Player.STATE_READY: return "READY"; default: return "?"; } }
Example 16
Source File: SingleMediaManager.java From ChatMessagesAdapter-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void parsePlayerEvent(int playbackState) { switch (playbackState) { case Player.STATE_BUFFERING: break; case Player.STATE_ENDED: notifyListenersOnStop(); break; case Player.STATE_IDLE: break; case Player.STATE_READY: break; default: break; } }
Example 17
Source File: MediaViewerActivity.java From Pix-Art-Messenger with GNU General Public License v3.0 | 4 votes |
private boolean isPlaying() { return player != null && player.getPlaybackState() != Player.STATE_ENDED && player.getPlaybackState() != Player.STATE_IDLE && player.getPlayWhenReady(); }
Example 18
Source File: CustomizeControlView.java From bcm-android with GNU General Public License v3.0 | 4 votes |
private boolean isPlaying() { return player != null && player.getPlaybackState() != Player.STATE_ENDED && player.getPlaybackState() != Player.STATE_IDLE && player.getPlayWhenReady(); }
Example 19
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 4 votes |
public void reset() { for (int i = 0; i < prevStates.length; i++) { prevStates[i] = Player.STATE_IDLE; } }
Example 20
Source File: MoviePlayingState.java From TubiPlayer with MIT License | 4 votes |
private void stopAdandPlayerMovie(PlayerUIController controller, PlayerAdLogicController componentController, MediaModel movieMedia) { SimpleExoPlayer adPlayer = controller.getAdPlayer(); SimpleExoPlayer moviePlayer = controller.getContentPlayer(); boolean shouldReprepareForSinglePlayer = PlayerDeviceUtils.useSinglePlayer() && controller.isPlayingAds; //first remove the AdPlayer's listener and pause the player adPlayer.removeAnalyticsListener(componentController.getAdPlayingMonitor()); if (shouldReprepareForSinglePlayer) { adPlayer.setPlayWhenReady(false); } //then update the playerView with SimpleExoPlayer and Movie MediaModel TubiExoPlayerView tubiExoPlayerView = (TubiExoPlayerView) controller.getExoPlayerView(); tubiExoPlayerView.setPlayer(moviePlayer, componentController.getTubiPlaybackInterface()); tubiExoPlayerView.setMediaModel(movieMedia); //prepare the moviePlayer with data source and set it play boolean haveResumePosition = controller.getMovieResumePosition() != C.TIME_UNSET; boolean isPlayerIdle = moviePlayer.getPlaybackState() == Player.STATE_IDLE; if (shouldReprepareForSinglePlayer || isPlayerIdle) { moviePlayer.prepare(movieMedia.getMediaSource(), !haveResumePosition, false); updatePlayerPosition(moviePlayer, controller); } moviePlayer.setPlayWhenReady(true); controller.isPlayingAds = false; hideVpaidNShowPlayer(controller); //when return to the movie playing state, show the subtitle if necessary if (shouldShowSubtitle()) { ((TubiExoPlayerView) controller.getExoPlayerView()).getSubtitleView().setVisibility(View.VISIBLE); } }