本文整理匯總了Java中com.google.android.exoplayer2.ExoPlayer類的典型用法代碼示例。如果您正苦於以下問題:Java ExoPlayer類的具體用法?Java ExoPlayer怎麽用?Java ExoPlayer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ExoPlayer類屬於com.google.android.exoplayer2包,在下文中一共展示了ExoPlayer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleMessage
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case SHOW_PROGRESS:
if (player != null
&& player.getPlaybackState() == ExoPlayer.STATE_READY
&& player.getPlayWhenReady()
) {
long pos = player.getCurrentPosition();
eventEmitter.progressChanged(pos, player.getBufferedPercentage());
msg = obtainMessage(SHOW_PROGRESS);
sendMessageDelayed(msg, 1000 - (pos % 1000));
}
break;
}
}
示例2: startPlayback
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
private void startPlayback() {
if (player != null) {
switch (player.getPlaybackState()) {
case ExoPlayer.STATE_IDLE:
case ExoPlayer.STATE_ENDED:
initializePlayer();
break;
case ExoPlayer.STATE_BUFFERING:
case ExoPlayer.STATE_READY:
if (!player.getPlayWhenReady()) {
setPlayWhenReady(true);
}
break;
default:
break;
}
} else {
initializePlayer();
}
if (!disableFocus) {
setKeepScreenOn(true);
}
}
示例3: attachPlayer
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
@Override
public void attachPlayer(ExoPlayer player, EventListener eventListener, ViewGroup adUiViewGroup) {
this.player = player;
this.eventListener = eventListener;
this.adUiViewGroup = adUiViewGroup;
lastAdProgress = null;
lastContentProgress = null;
adDisplayContainer.setAdContainer(adUiViewGroup);
player.addListener(this);
if (adPlaybackState != null) {
eventListener.onAdPlaybackState(adPlaybackState.copy());
if (imaPausedContent && player.getPlayWhenReady()) {
adsManager.resume();
}
} else {
requestAds();
}
}
示例4: updateResumePosition
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
/**
* update the movie and ad playing position when players are released
*/
@Override
protected void updateResumePosition() {
super.updateResumePosition();
//keep track of movie player's position when activity resume back
if (mTubiExoPlayer != null && playerUIController != null && mTubiExoPlayer.getPlaybackState() != ExoPlayer.STATE_IDLE) {
int resumeWindow = mTubiExoPlayer.getCurrentWindowIndex();
long resumePosition = mTubiExoPlayer.isCurrentWindowSeekable() ? Math.max(0, mTubiExoPlayer.getCurrentPosition())
: C.TIME_UNSET;
playerUIController.setMovieResumeInfo(resumeWindow, resumePosition);
}
//keep track of ad player's position when activity resume back, only keep track when current state is in AdPlayingState.
if (fsmPlayer.getCurrentState() instanceof AdPlayingState && adPlayer != null && playerUIController != null && adPlayer.getPlaybackState() != ExoPlayer.STATE_IDLE) {
int ad_resumeWindow = adPlayer.getCurrentWindowIndex();
long ad_resumePosition = adPlayer.isCurrentWindowSeekable() ? Math.max(0, adPlayer.getCurrentPosition())
: C.TIME_UNSET;
playerUIController.setAdResumeInfo(ad_resumeWindow, ad_resumePosition);
}
}
示例5: seekOrSkip
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
private void seekOrSkip() {
if (fsmPlayer == null) {
return;
}
if (fsmPlayer instanceof FsmPlayer) {
if (((FsmPlayer) fsmPlayer).getController() != null) {
SimpleExoPlayer adPlayer = ((FsmPlayer) fsmPlayer).getController().getAdPlayer();
if (adPlayer != null && adPlayer.getPlaybackState() == ExoPlayer.STATE_BUFFERING) {
long position = adPlayer.getCurrentPosition() + 1000 < adPlayer.getDuration() ? adPlayer.getCurrentPosition() + 1000 : adPlayer.getDuration();
adPlayer.seekTo(position);
adPlayer.setPlayWhenReady(true);
return;
}
}
}
}
示例6: updateMovieResumePosition
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
/**
* update the resume position of the main movice
*
* @param controller
*/
public static void updateMovieResumePosition(PlayerUIController controller) {
if (controller == null) {
return;
}
SimpleExoPlayer moviePlayer = controller.getContentPlayer();
if (moviePlayer != null && moviePlayer.getPlaybackState() != ExoPlayer.STATE_IDLE) {
int resumeWindow = moviePlayer.getCurrentWindowIndex();
long resumePosition = moviePlayer.isCurrentWindowSeekable() ? Math.max(0, moviePlayer.getCurrentPosition())
: C.TIME_UNSET;
controller.setMovieResumeInfo(resumeWindow, resumePosition);
}
}
示例7: performWorkAndupdatePlayerUI
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
@Override
public void performWorkAndupdatePlayerUI(@Nullable FsmPlayer fsmPlayer, @NonNull PlayerUIController controller, @NonNull PlayerComponentController componentController, @NonNull MediaModel movieMedia, @Nullable AdMediaModel adMedia) {
// doesn't need to do any UI work.
if (isNull(fsmPlayer, controller, componentController, movieMedia, adMedia)) {
return;
}
SimpleExoPlayer moviePlayer = controller.getContentPlayer();
// this mean, user jump out of the activity lifecycle in ReceivedAdState.
if (moviePlayer!=null && moviePlayer.getPlaybackState() == ExoPlayer.STATE_IDLE) {
fsmPlayer.transit(Input.ERROR);
}
}
示例8: onPlayerStateChanged
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
@Override
public final void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
Log.d(tag, "state [" + playWhenReady + ", " + playbackState + "]");
playerWasPrepared |= playbackState != ExoPlayer.STATE_IDLE;
if (playbackState == ExoPlayer.STATE_ENDED
|| (playbackState == ExoPlayer.STATE_IDLE && playerWasPrepared)) {
playerFinished = true;
}
boolean playing = playWhenReady && playbackState == ExoPlayer.STATE_READY;
if (!this.playing && playing) {
lastPlayingStartTimeMs = SystemClock.elapsedRealtime();
} else if (this.playing && !playing) {
totalPlayingTimeMs += SystemClock.elapsedRealtime() - lastPlayingStartTimeMs;
}
this.playing = playing;
}
示例9: onPlayerStateChanged
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
@Override
public void onPlayerStateChanged(boolean b, int i) {
Log.e("ExoMedia", "onPlayerStateChanged " + b + i);
if (i == ExoPlayer.STATE_READY) {
if (!isPrepar) {
isPrepar = true;
iMediaCallback.onPrepared(this);//第一次初始化
}
//緩衝好了
iMediaCallback.onInfo(this, MEDIA_INFO_BUFFERING_END, MEDIA_INFO_BUFFERING_END);
mainThreadHandler.removeCallbacks(runnable);
mainThreadHandler.post(runnable);
}
//播放完畢
if (i == ExoPlayer.STATE_ENDED) {
mainThreadHandler.removeCallbacks(runnable);
iMediaCallback.onCompletion(this);
}
if (i == ExoPlayer.STATE_BUFFERING)
iMediaCallback.onInfo(this, MEDIA_INFO_BUFFERING_START, MEDIA_INFO_BUFFERING_START);
}
示例10: onPlayerStateChanged
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
switch (playbackState) {
case ExoPlayer.STATE_ENDED:
//Log.d(TAG, "player state -> STATE_ENDED");
mPlayer.stop();
break;
case ExoPlayer.STATE_IDLE:
//Log.d(TAG, "player state -> STATE_IDLE");
break;
case ExoPlayer.STATE_READY:
//Log.d(TAG, "player state -> STATE_READY");
break;
case ExoPlayer.STATE_BUFFERING:
// Log.d(TAG, "player state -> STATE_BUFFERING");
break;
default:
break;
}
}
示例11: onClick
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
@Override
public void onClick(View v) {
if (v == playView && player != null) {
if (player.getPlaybackState() == ExoPlayer.STATE_ENDED) {
player.seekTo(0);
player.setPlayWhenReady(true);
} else {
player.setPlayWhenReady(!player.getPlayWhenReady());
}
} else if (v == fullscreen) {
Intent playerIntent = new Intent(getContext(), VideoPlayerActivity.class);
playerIntent.putExtra("uri", uri);
playerIntent.putExtra("position", player.getCurrentPosition());
playerIntent.putExtra("windowIndex", player.getCurrentWindowIndex());
playerIntent.putExtra("rotation", getWidth() > getHeight());
getContext().startActivity(playerIntent);
disconnect();
playerInstance.startFullScreenMode();
} else if (v == videoView) {
if (isConnected) {
show();
} else {
connect();
}
}
}
示例12: onPlayerStateChanged
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
switch (playbackState) {
case ExoPlayer.STATE_BUFFERING:
case ExoPlayer.STATE_READY:
replayImageButton.setVisibility(View.GONE);
exoButtonsFrameLayout.setVisibility(View.VISIBLE);
break;
case ExoPlayer.STATE_ENDED:
exoButtonsFrameLayout.setVisibility(View.GONE);
replayImageButton.setVisibility(View.VISIBLE);
break;
default:
break;
}
}
示例13: onPlayerStateChanged
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
switch (playbackState) {
case ExoPlayer.STATE_BUFFERING:
replayImageButton.setVisibility(View.GONE);
exoButtonsFrameLayout.setVisibility(View.VISIBLE);
break;
case ExoPlayer.STATE_READY:
replayImageButton.setVisibility(View.GONE);
exoButtonsFrameLayout.setVisibility(View.VISIBLE);
break;
case ExoPlayer.STATE_ENDED:
exoButtonsFrameLayout.setVisibility(View.GONE);
replayImageButton.setVisibility(View.VISIBLE);
break;
default:
break;
}
}
示例14: run
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
@Override
public void run() {
int state = mediaPlayer.getPlaybackState();
if (state == ExoPlayer.STATE_READY) {
long pos = mediaPlayer.getCurrentPosition();
float speed = mediaPlayer.getPlaybackParameters().speed;
if (!notificationManager.startNotification()) {
notificationManager.updateNotification();
}
stateBuilder.setBufferedPosition(mediaPlayer.getBufferedPercentage());
int sessionState = mediaPlayer.getPlayWhenReady() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED;
mediaSession.setPlaybackState(stateBuilder.setState(sessionState, pos, speed).build());
if (mediaPlayer.getPlayWhenReady()) {
progressHandler.postDelayed(progressRunnable, 1000 - (pos % 1000));
}
}
}
示例15: getState
import com.google.android.exoplayer2.ExoPlayer; //導入依賴的package包/類
@Override
public int getState()
{
if (exoPlayer == null) {
return exoPlayerNullIsStopped
? PlaybackStateCompat.STATE_STOPPED
: PlaybackStateCompat.STATE_NONE;
}
switch (exoPlayer.getPlaybackState()) {
case ExoPlayer.STATE_IDLE:
return PlaybackStateCompat.STATE_PAUSED;
case ExoPlayer.STATE_BUFFERING:
return PlaybackStateCompat.STATE_BUFFERING;
case ExoPlayer.STATE_READY:
return exoPlayer.getPlayWhenReady()
? PlaybackStateCompat.STATE_PLAYING
: PlaybackStateCompat.STATE_PAUSED;
case ExoPlayer.STATE_ENDED:
return PlaybackStateCompat.STATE_PAUSED;
default:
return PlaybackStateCompat.STATE_NONE;
}
}