com.google.android.exoplayer2.Player Java Examples
The following examples show how to use
com.google.android.exoplayer2.Player.
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: CustomizeControlView.java From bcm-android with GNU General Public License v3.0 | 6 votes |
public void setRepeatToggleModes(@RepeatModeUtil.RepeatToggleModes int repeatToggleModes) { this.repeatToggleModes = repeatToggleModes; if (player != null) { @Player.RepeatMode int currentMode = player.getRepeatMode(); if (repeatToggleModes == RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE && currentMode != Player.REPEAT_MODE_OFF) { controlDispatcher.dispatchSetRepeatMode(player, Player.REPEAT_MODE_OFF); } else if (repeatToggleModes == RepeatModeUtil.REPEAT_TOGGLE_MODE_ONE && currentMode == Player.REPEAT_MODE_ALL) { controlDispatcher.dispatchSetRepeatMode(player, Player.REPEAT_MODE_ONE); } else if (repeatToggleModes == RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL && currentMode == Player.REPEAT_MODE_ONE) { controlDispatcher.dispatchSetRepeatMode(player, Player.REPEAT_MODE_ALL); } } }
Example #2
Source File: StreamFragment.java From Twire with GNU General Public License v3.0 | 6 votes |
@Override public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) { if (playbackState == Player.STATE_READY) { mBufferingView.stop(); hideVideoInterface(); delayHiding(); Log.d(LOG_TAG, "Render Start"); if (!previewInbackGround) { hidePreview(); } } else if (playbackState == Player.STATE_BUFFERING) { mBufferingView.start(); delayAnimationHandler.removeCallbacks(hideAnimationRunnable); showVideoInterface(); Log.d(LOG_TAG, "Render stop. Buffering start"); } }
Example #3
Source File: LoopingMediaSource.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public int getPreviousWindowIndex(int windowIndex, @Player.RepeatMode int repeatMode, boolean shuffleModeEnabled) { int childPreviousWindowIndex = timeline.getPreviousWindowIndex(windowIndex, repeatMode, shuffleModeEnabled); return childPreviousWindowIndex == C.INDEX_UNSET ? getLastWindowIndex(shuffleModeEnabled) : childPreviousWindowIndex; }
Example #4
Source File: ExoPlayerView.java From DanDanPlayForAndroid with MIT License | 5 votes |
/** * 视频是否正在播放 */ private boolean isVideoPlaying() { if (mVideoView != null && mVideoView.getPlayer() != null) { if (mVideoView.getPlayer().getPlayWhenReady()) { return mVideoView.getPlayer().getPlaybackState() == Player.STATE_READY; } } return false; }
Example #5
Source File: VideoPlayer.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { maybeReportPlayerState(); if (playWhenReady && playbackState == Player.STATE_READY) { NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.playerDidStartPlaying, this); } if (!videoPlayerReady && playbackState == Player.STATE_READY) { videoPlayerReady = true; checkPlayersReady(); } }
Example #6
Source File: EventLogger.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@Override public void onTimelineChanged(EventTime eventTime, @Player.TimelineChangeReason int reason) { int periodCount = eventTime.timeline.getPeriodCount(); int windowCount = eventTime.timeline.getWindowCount(); logd( "timelineChanged [" + getEventTimeString(eventTime) + ", periodCount=" + periodCount + ", windowCount=" + windowCount + ", reason=" + getTimelineChangeReasonString(reason)); for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) { eventTime.timeline.getPeriod(i, period); logd(" " + "period [" + getTimeString(period.getDurationMs()) + "]"); } if (periodCount > MAX_TIMELINE_ITEM_LINES) { logd(" ..."); } for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) { eventTime.timeline.getWindow(i, window); logd( " " + "window [" + getTimeString(window.getDurationMs()) + ", " + window.isSeekable + ", " + window.isDynamic + "]"); } if (windowCount > MAX_TIMELINE_ITEM_LINES) { logd(" ..."); } logd("]"); }
Example #7
Source File: ProviderTvInputService.java From xipl with Apache License 2.0 | 5 votes |
@Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playWhenReady && playbackState == Player.STATE_READY) { notifyTracksChanged(getAllTracks()); notifyTrackSelected(TvTrackInfo.TYPE_VIDEO, getTrackId(TvTrackInfo.TYPE_VIDEO)); notifyTrackSelected(TvTrackInfo.TYPE_AUDIO, getTrackId(TvTrackInfo.TYPE_AUDIO)); notifyVideoAvailable(); } if (DEBUG) { Log.d(getClass().getSimpleName(), "Player state changed to " + playbackState + ", PWR: " + playWhenReady); } }
Example #8
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 #9
Source File: United.java From United4 with GNU General Public License v3.0 | 5 votes |
public static void onCompletion(Player player) { boolean looping = P.getBool("looping"); boolean shuffling = P.getBool("shuffle"); // If we're looping, play the song again if (looping) { player.seekTo(0); player.setPlayWhenReady(true); return; } int idx; try { // Get the list of all songs JSONArray parsed = new JSONArray(P.get("ordered_songs")); List<String> all_songs = new ArrayList<>(); for (int i = 0; i < parsed.length(); i++) { all_songs.add(parsed.getString(i)); } // If we're shuffling, get a random index if (shuffling) { idx = new Random().nextInt(all_songs.size()); } else { // otherwise, find the current index and add one idx = all_songs.indexOf(P.get("current_song")); idx = (idx + 1) % all_songs.size(); } // Figure out what song we're supposed to play String next_song = all_songs.get(idx); // Play it and notify music.html if it's up. For more information see the documentation for // NotifierService playSong(next_song, true); } catch (Exception ignored) { // } }
Example #10
Source File: LoopingMediaSource.java From MediaSDK with Apache License 2.0 | 5 votes |
@Override public int getPreviousWindowIndex(int windowIndex, @Player.RepeatMode int repeatMode, boolean shuffleModeEnabled) { int childPreviousWindowIndex = timeline.getPreviousWindowIndex(windowIndex, repeatMode, shuffleModeEnabled); return childPreviousWindowIndex == C.INDEX_UNSET ? getLastWindowIndex(shuffleModeEnabled) : childPreviousWindowIndex; }
Example #11
Source File: RepeatModeUtil.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Verifies whether a given {@code repeatMode} is enabled in the bitmask {@code enabledModes}. * * @param repeatMode The mode to check. * @param enabledModes The bitmask representing the enabled modes. * @return {@code true} if enabled. */ public static boolean isRepeatModeEnabled(@Player.RepeatMode int repeatMode, int enabledModes) { switch (repeatMode) { case Player.REPEAT_MODE_OFF: return true; case Player.REPEAT_MODE_ONE: return (enabledModes & REPEAT_TOGGLE_MODE_ONE) != 0; case Player.REPEAT_MODE_ALL: return (enabledModes & REPEAT_TOGGLE_MODE_ALL) != 0; default: return false; } }
Example #12
Source File: ExoPlayerHelper.java From ExoPlayer-Wrapper with Apache License 2.0 | 5 votes |
/** * ExoPlayer Player.EventListener methods */ @Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { if (mExoPlayerListener != null) { mExoPlayerListener.onTracksChanged( mPlayer.getCurrentWindowIndex(), getNextWindowIndex(), mPlayer.getPlaybackState() == Player.STATE_READY); } }
Example #13
Source File: AbstractConcatenatedTimeline.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public int getPreviousWindowIndex(int windowIndex, @Player.RepeatMode int repeatMode, boolean shuffleModeEnabled) { if (isAtomic) { // Adapt repeat and shuffle mode to atomic concatenation. repeatMode = repeatMode == Player.REPEAT_MODE_ONE ? Player.REPEAT_MODE_ALL : repeatMode; shuffleModeEnabled = false; } // Find previous window within current child. int childIndex = getChildIndexByWindowIndex(windowIndex); int firstWindowIndexInChild = getFirstWindowIndexByChildIndex(childIndex); int previousWindowIndexInChild = getTimelineByChildIndex(childIndex).getPreviousWindowIndex( windowIndex - firstWindowIndexInChild, repeatMode == Player.REPEAT_MODE_ALL ? Player.REPEAT_MODE_OFF : repeatMode, shuffleModeEnabled); if (previousWindowIndexInChild != C.INDEX_UNSET) { return firstWindowIndexInChild + previousWindowIndexInChild; } // If not found, find last window of previous non-empty child. int previousChildIndex = getPreviousChildIndex(childIndex, shuffleModeEnabled); while (previousChildIndex != C.INDEX_UNSET && getTimelineByChildIndex(previousChildIndex).isEmpty()) { previousChildIndex = getPreviousChildIndex(previousChildIndex, shuffleModeEnabled); } if (previousChildIndex != C.INDEX_UNSET) { return getFirstWindowIndexByChildIndex(previousChildIndex) + getTimelineByChildIndex(previousChildIndex).getLastWindowIndex(shuffleModeEnabled); } // If not found, this is the first window. if (repeatMode == Player.REPEAT_MODE_ALL) { return getLastWindowIndex(shuffleModeEnabled); } return C.INDEX_UNSET; }
Example #14
Source File: QBPlaybackControlView.java From ChatMessagesAdapter-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void updateViewState() { if(getPlayer().getPlaybackState() == Player.STATE_ENDED){ resetPlayerPosition(); } else { updatePlayPauseIconView(); } }
Example #15
Source File: EventLogger.java From TelePlus-Android 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 #16
Source File: AnalyticsCollector.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public final void onTimelineChanged( Timeline timeline, Object manifest, @Player.TimelineChangeReason int reason) { mediaPeriodQueueTracker.onTimelineChanged(timeline); EventTime eventTime = generatePlayingMediaPeriodEventTime(); for (AnalyticsListener listener : listeners) { listener.onTimelineChanged(eventTime, reason); } }
Example #17
Source File: FileViewFragment.java From lbry-android with MIT License | 5 votes |
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 #18
Source File: ExoPlayerView.java From DanDanPlayForAndroid with MIT License | 5 votes |
/** * 开始播放 */ public void start() { //第一次播放时 if (mIsNeverPlay) { mIsNeverPlay = false; //显示加载动画 mLoadingView.setVisibility(VISIBLE); mIsShowBar = false; //装载弹幕 mDanmakuView.prepare(mDanmakuParser, mDanmakuContext); //查询网络字幕 if (isQueryNetworkSubtitle && mOutsideListener != null) { mOutsideListener.onAction(Constants.INTENT_QUERY_SUBTITLE, 0); } } //切换播放按钮状态 bottomBarView.setPlayIvStatus(true); //设置可以播放 exoPlayer.setPlayWhenReady(true); //启动播放 controlDispatcher.dispatchSetPlayWhenReady(exoPlayer, true); // 更新进度 mHandler.sendEmptyMessage(MSG_UPDATE_SEEK); //已播放结束后,再点击播放,重新设置弹幕播放进度 if (exoPlayer.getPlaybackState() == Player.STATE_ENDED) { controlDispatcher.dispatchSeekTo(exoPlayer, exoPlayer.getCurrentWindowIndex(), C.TIME_UNSET); if (mDanmakuView != null && mDanmakuView.isPrepared()) { mDanmakuView.seekTo((long) 0 - topBarView.getDanmuSettingView().getDanmuExtraTime()); mDanmakuView.pause(); } } //已加载字幕,则播放字幕 if (topBarView.getSubtitleSettingView().isLoadSubtitle()) subtitleManager.showExSub(); }
Example #19
Source File: EventLogger.java From MediaSDK with Apache License 2.0 | 5 votes |
@Override public void onTimelineChanged(EventTime eventTime, @Player.TimelineChangeReason int reason) { int periodCount = eventTime.timeline.getPeriodCount(); int windowCount = eventTime.timeline.getWindowCount(); logd( "timeline [" + getEventTimeString(eventTime) + ", periodCount=" + periodCount + ", windowCount=" + windowCount + ", reason=" + getTimelineChangeReasonString(reason)); for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) { eventTime.timeline.getPeriod(i, period); logd(" " + "period [" + getTimeString(period.getDurationMs()) + "]"); } if (periodCount > MAX_TIMELINE_ITEM_LINES) { logd(" ..."); } for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) { eventTime.timeline.getWindow(i, window); logd( " " + "window [" + getTimeString(window.getDurationMs()) + ", " + window.isSeekable + ", " + window.isDynamic + "]"); } if (windowCount > MAX_TIMELINE_ITEM_LINES) { logd(" ..."); } logd("]"); }
Example #20
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 #21
Source File: ExoPlayerFragment.java From carstream-android-auto with Apache License 2.0 | 5 votes |
@Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playbackState == Player.STATE_BUFFERING) { BroadcastFromUI.broadCastLoading(getContext()); } else if (playbackState == Player.STATE_ENDED) { BroadcastFromUI.broadCastPaused(getContext(), String.valueOf(titleView.getText())); } else if (playWhenReady && playbackState == Player.STATE_READY) { BroadcastFromUI.broadCastPlaying(getContext(), String.valueOf(titleView.getText())); playerFocusHelper.play(); } else if (playWhenReady) { BroadcastFromUI.broadCastLoading(getContext()); } else { BroadcastFromUI.broadCastPaused(getContext(), String.valueOf(titleView.getText())); } }
Example #22
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 #23
Source File: ExoPlayerHelper.java From ExoPlayer-Wrapper with Apache License 2.0 | 5 votes |
@Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (mExoPlayerListener == null || mPlayer == null) { return; } switch (playbackState) { case Player.STATE_READY: if (playWhenReady) { onPlayerPlaying(); mExoPlayerListener.onPlayerPlaying(mPlayer.getCurrentWindowIndex()); } else { onPlayerPaused(); mExoPlayerListener.onPlayerPaused(mPlayer.getCurrentWindowIndex()); } break; case Player.STATE_BUFFERING: onPlayerBuffering(); mExoPlayerListener.onPlayerBuffering(mPlayer.getCurrentWindowIndex()); break; case Player.STATE_ENDED: mExoPlayerListener.onPlayerStateEnded(mPlayer.getCurrentWindowIndex()); break; case Player.STATE_IDLE: mExoPlayerListener.onPlayerStateIdle(mPlayer.getCurrentWindowIndex()); break; default: Log.e("ExoPlayerHelper-zaq", "onPlayerStateChanged unknown: " + playbackState); } }
Example #24
Source File: QueuedExoPlayer.java From Jockey with Apache License 2.0 | 5 votes |
private int getExoPlayerRepeatMode() { if (mRepeatAll) { return Player.REPEAT_MODE_ALL; } else if (mRepeatOne) { return Player.REPEAT_MODE_ONE; } else { return Player.REPEAT_MODE_OFF; } }
Example #25
Source File: CustomizePlayerView.java From bcm-android with GNU General Public License v3.0 | 5 votes |
private void updateBuffering() { if (bufferingView != null) { boolean showBufferingSpinner = showBuffering && player != null && player.getPlaybackState() == Player.STATE_BUFFERING && player.getPlayWhenReady(); bufferingView.setVisibility(showBufferingSpinner ? View.VISIBLE : View.GONE); } }
Example #26
Source File: CustomizePlayerView.java From bcm-android with GNU General Public License v3.0 | 5 votes |
private boolean shouldShowControllerIndefinitely() { if (player == null) { return true; } int playbackState = player.getPlaybackState(); return controllerAutoShow && (playbackState == Player.STATE_IDLE || playbackState == Player.STATE_ENDED || !player.getPlayWhenReady()); }
Example #27
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 #28
Source File: AnalyticsCollector.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Creates an analytics collector for the specified player. * * @param player The {@link Player} for which data will be collected. Can be null, if the player * is set by calling {@link AnalyticsCollector#setPlayer(Player)} before using the analytics * collector. * @param clock A {@link Clock} used to generate timestamps. */ protected AnalyticsCollector(@Nullable Player player, Clock clock) { if (player != null) { this.player = player; } this.clock = Assertions.checkNotNull(clock); listeners = new CopyOnWriteArraySet<>(); mediaPeriodQueueTracker = new MediaPeriodQueueTracker(); window = new Window(); }
Example #29
Source File: CustomizePlayerView.java From bcm-android with GNU General Public License v3.0 | 5 votes |
public static void switchTargetView( @NonNull Player player, @Nullable CustomizePlayerView oldPlayerView, @Nullable CustomizePlayerView newPlayerView) { if (oldPlayerView == newPlayerView) { return; } if (newPlayerView != null) { newPlayerView.setPlayer(player); } if (oldPlayerView != null) { oldPlayerView.setPlayer(null); } }
Example #30
Source File: CustomizeControlView.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@Override public void onTimelineChanged( Timeline timeline, Object manifest, @Player.TimelineChangeReason int reason) { updateNavigation(); updateTimeBarMode(); updateProgress(); }