Java Code Examples for com.google.android.exoplayer2.Player#STATE_ENDED

The following examples show how to use com.google.android.exoplayer2.Player#STATE_ENDED . 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: LocalPlayback.java    From klingar with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: ReactExoplayerView.java    From react-native-video with MIT License 6 votes vote down vote up
private void startPlayback() {
    if (player != null) {
        switch (player.getPlaybackState()) {
            case Player.STATE_IDLE:
            case Player.STATE_ENDED:
                initializePlayer();
                break;
            case Player.STATE_BUFFERING:
            case Player.STATE_READY:
                if (!player.getPlayWhenReady()) {
                    setPlayWhenReady(true);
                }
                break;
            default:
                break;
        }

    } else {
        initializePlayer();
    }
    if (!disableFocus) {
        setKeepScreenOn(preventsDisplaySleepDuringVideoPlayback);
    }
}
 
Example 3
Source File: ExoPlayerImpl.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@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 vote down vote up
@Override @State public int getState() {
  if (exoPlayer == null) {
    return exoPlayerNullIsStopped ? PlaybackStateCompat.STATE_STOPPED
        : PlaybackStateCompat.STATE_NONE;
  }
  switch (exoPlayer.getPlaybackState()) {
    case Player.STATE_IDLE:
    case Player.STATE_ENDED:
      return PlaybackStateCompat.STATE_PAUSED;
    case Player.STATE_BUFFERING:
      return PlaybackStateCompat.STATE_BUFFERING;
    case Player.STATE_READY:
      return exoPlayer.getPlayWhenReady() ? PlaybackStateCompat.STATE_PLAYING
          : PlaybackStateCompat.STATE_PAUSED;
    default:
      return PlaybackStateCompat.STATE_NONE;
  }
}
 
Example 5
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
/**
 * Seeks to the beginning of the media, and plays it. This method will not succeed if playback state is not {@code ExoPlayer.STATE_IDLE} or {@code ExoPlayer.STATE_ENDED}.
 *
 * @return {@code true} if the media was successfully restarted, otherwise {@code false}
 */
public boolean restart() {
    int playbackState = getPlaybackState();
    if (playbackState != Player.STATE_IDLE && playbackState != Player.STATE_ENDED) {
        return false;
    }

    seekTo(0);
    setPlayWhenReady(true);

    forcePrepare();
    prepare();

    return true;
}
 
Example 6
Source File: EventLogger.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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 7
Source File: ExoMediaPlayer.java    From VideoDemoJava with MIT License 5 votes vote down vote up
@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 8
Source File: FileViewFragment.java    From lbry-android with MIT License 5 votes vote down vote up
private void setCurrentPlayer(Player currentPlayer) {
    if (this.currentPlayer == currentPlayer) {
        return;
    }

    // View management.
    if (currentPlayer == MainActivity.appPlayer) {
        //localPlayerView.setVisibility(View.VISIBLE);
        castControlView.hide();
        ((ImageView) getView().findViewById(R.id.player_image_cast_toggle)).setImageResource(R.drawable.ic_cast);
    } else /* currentPlayer == castPlayer */ {
        castControlView.show();
        ((ImageView) getView().findViewById(R.id.player_image_cast_toggle)).setImageResource(R.drawable.ic_cast_connected);
    }

    // Player state management.
    long playbackPositionMs = C.TIME_UNSET;
    int windowIndex = C.INDEX_UNSET;
    boolean playWhenReady = false;

    Player previousPlayer = this.currentPlayer;
    if (previousPlayer != null) {
        // Save state from the previous player.
        int playbackState = previousPlayer.getPlaybackState();
        if (playbackState != Player.STATE_ENDED) {
            playbackPositionMs = previousPlayer.getCurrentPosition();
            playWhenReady = previousPlayer.getPlayWhenReady();
        }
        previousPlayer.stop(true);
    }

    this.currentPlayer = currentPlayer;

    // Media queue management.
    /*if (currentPlayer == exoPlayer) {
        exoPlayer.prepare(concatenatingMediaSource);
    }*/
    currentPlayer.seekTo(playbackPositionMs);
    currentPlayer.setPlayWhenReady(true);
}
 
Example 9
Source File: SingleMediaManager.java    From ChatMessagesAdapter-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 10
Source File: AdPlayingMonitor.java    From TubiPlayer with MIT License 5 votes vote down vote up
@Override
public void onPlayerStateChanged(EventTime eventTime, boolean playWhenReady, int playbackState) {
    super.onPlayerStateChanged(eventTime, playWhenReady, playbackState);

    //the last ad has finish playing.
    if (playbackState == Player.STATE_ENDED && playWhenReady == true) {
        fsmPlayer.removePlayedAdAndTransitToNextState();
    }
}
 
Example 11
Source File: ScreenDimmingVideoEventListener.java    From zapp with MIT License 5 votes vote down vote up
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
	View view = viewToKeepScreenOn.get();

	if (view == null) {
		return;
	}

	if (playbackState == Player.STATE_IDLE || playbackState == Player.STATE_ENDED || !playWhenReady) {
		view.setKeepScreenOn(false);
	} else {
		// This prevents the screen from getting dim/lock
		view.setKeepScreenOn(true);
	}
}
 
Example 12
Source File: CustomPlayBackController.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
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 13
Source File: CustomizeControlView.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View view) {
    if (player != null) {
        if (nextButton == view) {
            next();
        } else if (previousButton == view) {
            previous();
        } else if (fastForwardButton == view) {
            fastForward();
        } else if (rewindButton == view) {
            rewind();
        } else if (playButton == view || centerPlayButton == view) {
            if (playIconOnclickListener == null || !playIconOnclickListener.playIconClicked()) {
                if (player.getPlaybackState() == Player.STATE_IDLE) {
                    if (playbackPreparer != null) {
                        playbackPreparer.preparePlayback();
                    }
                } else if (player.getPlaybackState() == Player.STATE_ENDED) {
                    controlDispatcher.dispatchSeekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET);
                }
                controlDispatcher.dispatchSetPlayWhenReady(player, true);
            }
        } else if (pauseButton == view) {
            controlDispatcher.dispatchSetPlayWhenReady(player, false);
        } else if (repeatToggleButton == view) {
            controlDispatcher.dispatchSetRepeatMode(
                    player, RepeatModeUtil.getNextRepeatMode(player.getRepeatMode(), repeatToggleModes));
        } else if (shuffleButton == view) {
            controlDispatcher.dispatchSetShuffleModeEnabled(player, !player.getShuffleModeEnabled());
        }
    }
    hideAfterTimeout();
}
 
Example 14
Source File: VideoPlayer.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
    switch (playbackState) {
        case Player.STATE_READY:
            state = PlayerState.PREPARED;
            if (callback != null) {
                callback.onPrepared();
            }

            if (playWhenReady) {
                state = PlayerState.PLAYING;
            }
            break;
        case Player.STATE_ENDED:
            // onPlayerStateChanged with Player.STATE_ENDED called twice after calling
            // setPlayWhenReady(false) in STATE_ENDED
            // so if already called then avoid on completion again.
            if (state == PlayerState.PLAYBACK_COMPLETE)
                return;
            // sometimes, error also causes onCompletion() call
            // avoid on completion if player got an error
            if (state != PlayerState.ERROR) {
                state = PlayerState.PLAYBACK_COMPLETE;
                if (callback != null) {
                    callback.onPlaybackComplete();
                }
                seekTo(0);
                exoPlayer.setPlayWhenReady(false);
                logger.debug("Playback complete");
            }
            break;
    }
}
 
Example 15
Source File: EventLogger.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
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: EventLogger.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
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 17
Source File: OnCompletionStateChangedForwarder.java    From no-player with Apache License 2.0 4 votes vote down vote up
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
    if (playbackState == Player.STATE_ENDED) {
        stateChangedListener.onVideoStopped();
    }
}
 
Example 18
Source File: PlayerActivity.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
    if (playbackState == Player.STATE_ENDED)
        showControls();
    supportInvalidateOptionsMenu();
}
 
Example 19
Source File: CustomizeControlView.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
private boolean isPlaying() {
    return player != null
            && player.getPlaybackState() != Player.STATE_ENDED
            && player.getPlaybackState() != Player.STATE_IDLE
            && player.getPlayWhenReady();
}
 
Example 20
Source File: VideoPlayerActivity.java    From ChatMessagesAdapter-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
    if (playbackState == Player.STATE_ENDED) {
        setPlayerToStartPosition();
    }
}