com.google.android.exoplayer2.SimpleExoPlayer Java Examples
The following examples show how to use
com.google.android.exoplayer2.SimpleExoPlayer.
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: AdPlayingMonitor.java From TubiPlayer with MIT License | 6 votes |
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; } } } }
Example #2
Source File: ExoPlayerManager.java From PreviewSeekBar with Apache License 2.0 | 6 votes |
private SimpleExoPlayer createPlayer() { SimpleExoPlayer player = new SimpleExoPlayer.Builder(playerView.getContext()).build(); player.setPlayWhenReady(true); player.prepare(mediaSourceBuilder.getMediaSource(false)); player.addListener(eventListener); return player; }
Example #3
Source File: StreamFragment.java From Twire with GNU General Public License v3.0 | 6 votes |
private void initializePlayer() { if (player == null) { player = new SimpleExoPlayer.Builder(getContext()).build(); player.addListener(this); mVideoView.setPlayer(player); mVideoView.setPlaybackPreparer(this); if (currentMediaSource != null) player.prepare(currentMediaSource); mediaSession = new MediaSessionCompat(getContext(), getContext().getPackageName()); MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession); mediaSessionConnector.setPlayer(player); mediaSession.setActive(true); progressHandler.postDelayed(progressRunnable, 1000); } }
Example #4
Source File: ExoVideoView.java From ExoVideoView with Apache License 2.0 | 6 votes |
/** * Switches the view targeted by a given {@link SimpleExoPlayer}. * * @param player The player whose target view is being switched. * @param oldPlayerView The old view to detach from the player. * @param newPlayerView The new view to attach to the player. */ public static void switchTargetView(@NonNull SimpleExoPlayer player, @Nullable ExoVideoView oldPlayerView, @Nullable ExoVideoView newPlayerView) { if (oldPlayerView == newPlayerView) { return; } // We attach the new view before detaching the old one because this ordering allows the player // to swap directly from one surface to another, without transitioning through a state where no // surface is attached. This is significantly more efficient and achieves a more seamless // transition when using platform provided video decoders. if (newPlayerView != null) { newPlayerView.setPlayer(player); } if (oldPlayerView != null) { oldPlayerView.setPlayer(null); } }
Example #5
Source File: ReceiveAdState.java From TubiPlayer with MIT License | 6 votes |
@Override public void performWorkAndUpdatePlayerUI(@NonNull FsmPlayer fsmPlayer) { super.performWorkAndUpdatePlayerUI(fsmPlayer); // doesn't need to do any UI work. if (isNull(fsmPlayer)) { 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); } }
Example #6
Source File: FsmPlayer.java From TubiPlayer with MIT License | 6 votes |
/** * update the resume position of the main video * * @param controller */ public static void updateMovieResumePosition(PlayerUIController controller) { if (controller == null) { return; } SimpleExoPlayer moviePlayer = controller.getContentPlayer(); if (moviePlayer != null && moviePlayer.getPlaybackState() != Player.STATE_IDLE) { int resumeWindow = moviePlayer.getCurrentWindowIndex(); long resumePosition = moviePlayer.isCurrentWindowSeekable() ? Math.max(0, moviePlayer.getCurrentPosition()) : C.TIME_UNSET; controller.setMovieResumeInfo(resumeWindow, resumePosition); ExoPlayerLogger.i(Constants.FSMPLAYER_TESTING, resumePosition + ""); } }
Example #7
Source File: ExoMediaPlayer.java From DKVideoPlayer with Apache License 2.0 | 6 votes |
@Override public void initPlayer() { mInternalPlayer = new SimpleExoPlayer.Builder( mAppContext, mRenderersFactory == null ? mRenderersFactory = new DefaultRenderersFactory(mAppContext) : mRenderersFactory, mTrackSelector == null ? mTrackSelector = new DefaultTrackSelector(mAppContext) : mTrackSelector, mLoadControl == null ? mLoadControl = new DefaultLoadControl() : mLoadControl, DefaultBandwidthMeter.getSingletonInstance(mAppContext), Util.getLooper(), new AnalyticsCollector(Clock.DEFAULT), /* useLazyPreparation= */ true, Clock.DEFAULT) .build(); setOptions(); //播放器日志 if (VideoViewManager.getConfig().mIsEnableLog && mTrackSelector instanceof MappingTrackSelector) { mInternalPlayer.addAnalyticsListener(new EventLogger((MappingTrackSelector) mTrackSelector, "ExoPlayer")); } mInternalPlayer.addListener(this); mInternalPlayer.addVideoListener(this); }
Example #8
Source File: ExoPlayerAdapter.java From tv-samples with Apache License 2.0 | 6 votes |
private void prepareMediaForPlaying() { reset(); if (mMediaSourceUri != null) { MediaSource mediaSource = onCreateMediaSource(mMediaSourceUri); mPlayer.prepare(mediaSource); } else { return; } mPlayer.setAudioStreamType(mAudioStreamType); mPlayer.setVideoListener(new SimpleExoPlayer.VideoListener() { @Override public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) { getCallback().onVideoSizeChanged(ExoPlayerAdapter.this, width, height); } @Override public void onRenderedFirstFrame() { } }); notifyBufferingStartEnd(); getCallback().onPlayStateChanged(ExoPlayerAdapter.this); }
Example #9
Source File: ExoMediaPlayer.java From DKVideoPlayer with Apache License 2.0 | 6 votes |
@Override public void release() { if (mInternalPlayer != null) { mInternalPlayer.removeListener(this); mInternalPlayer.removeVideoListener(this); final SimpleExoPlayer player = mInternalPlayer; mInternalPlayer = null; new Thread() { @Override public void run() { //异步释放,防止卡顿 player.release(); } }.start(); } mIsPreparing = false; mIsBuffering = false; mLastReportedPlaybackState = Player.STATE_IDLE; mLastReportedPlayWhenReady = false; mSpeedPlaybackParameters = null; }
Example #10
Source File: ExoMediaPlayer.java From PlayerBase with Apache License 2.0 | 5 votes |
public ExoMediaPlayer(){ mAppContext = AppContextAttach.getApplicationContext(); RenderersFactory renderersFactory = new DefaultRenderersFactory(mAppContext); DefaultTrackSelector trackSelector = new DefaultTrackSelector(mAppContext); mInternalPlayer = new SimpleExoPlayer.Builder(mAppContext, renderersFactory) .setTrackSelector(trackSelector).build(); // Measures bandwidth during playback. Can be null if not required. mBandwidthMeter = new DefaultBandwidthMeter.Builder(mAppContext).build(); mInternalPlayer.addListener(mEventListener); }
Example #11
Source File: UserController.java From TubiPlayer with MIT License | 5 votes |
/** * Every time the {@link com.tubitv.media.fsm.state_machine.FsmPlayer} change states between * {@link com.tubitv.media.fsm.concrete.AdPlayingState} and {@link com.tubitv.media.fsm.concrete.MoviePlayingState}, * {@link UserController#mPlayer} instance need to update . * * @param player the current player that is playing the video */ public void setPlayer(@NonNull SimpleExoPlayer player, @NonNull PlaybackActionCallback playbackActionCallback, @NonNull TubiExoPlayerView tubiExoPlayerView) { if (player == null || tubiExoPlayerView == null) { ExoPlayerLogger.e(TAG, "setPlayer is null"); return; } if (this.mPlayer == player) { return; } mTubiExoPlayerView = tubiExoPlayerView; //remove the old listener if (mPlayer != null) { this.mPlayer.removeListener(this); } this.mPlayer = player; mPlayer.addListener(this); playerPlaybackState.set(mPlayer.getPlaybackState()); mPlaybackActionCallback = playbackActionCallback; updateProgress(); }
Example #12
Source File: MoviePlayingState.java From TubiPlayer with MIT License | 5 votes |
private void updatePlayerPosition(SimpleExoPlayer moviePlayer, PlayerUIController controller) { // if want to play movie from certain position when first open the movie if (controller.hasHistory()) { moviePlayer.seekTo(moviePlayer.getCurrentWindowIndex(), controller.getHistoryPosition()); controller.clearHistoryRecord(); return; } boolean haveResumePosition = controller.getMovieResumePosition() != C.TIME_UNSET; if (haveResumePosition) { moviePlayer.seekTo(moviePlayer.getCurrentWindowIndex(), controller.getMovieResumePosition()); } }
Example #13
Source File: ExoHostedTest.java From ExoPlayer-Offline with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") protected SimpleExoPlayer buildExoPlayer(HostActivity host, Surface surface, MappingTrackSelector trackSelector, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) { SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(host, trackSelector, new DefaultLoadControl(), drmSessionManager, SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF, 0); player.setVideoSurface(surface); return player; }
Example #14
Source File: PlayerUIController.java From TubiPlayer with MIT License | 5 votes |
public SimpleExoPlayer getAdPlayer() { // We'll reuse content player to play ads for single player instance case if (PlayerDeviceUtils.useSinglePlayer()) { return contentPlayer; } return adPlayer; }
Example #15
Source File: GLES30WallpaperRenderer.java From alynx-live-wallpaper with Apache License 2.0 | 5 votes |
@Override void setSourcePlayer(@NonNull final SimpleExoPlayer exoPlayer) { // Re-create SurfaceTexture when getting a new player. // Because maybe a new video is loaded. createSurfaceTexture(); exoPlayer.setVideoSurface(new Surface(surfaceTexture)); }
Example #16
Source File: DashTest.java From ExoPlayer-Offline with Apache License 2.0 | 5 votes |
@Override protected SimpleExoPlayer buildExoPlayer(HostActivity host, Surface surface, MappingTrackSelector trackSelector, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) { SimpleExoPlayer player = new DebugSimpleExoPlayer(host, trackSelector, new DefaultLoadControl(), drmSessionManager); player.setVideoSurface(surface); return player; }
Example #17
Source File: GLES20WallpaperRenderer.java From alynx-live-wallpaper with Apache License 2.0 | 5 votes |
@Override void setSourcePlayer(@NonNull final SimpleExoPlayer exoPlayer) { // Re-create SurfaceTexture when getting a new player. // Because maybe a new video is loaded. createSurfaceTexture(); exoPlayer.setVideoSurface(new Surface(surfaceTexture)); }
Example #18
Source File: Alarmio.java From Alarmio with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); DebugUtils.setup(this); prefs = PreferenceManager.getDefaultSharedPreferences(this); listeners = new ArrayList<>(); alarms = new ArrayList<>(); timers = new ArrayList<>(); player = new SimpleExoPlayer.Builder(this).build(); player.addListener(this); DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayer2example"), null); hlsMediaSourceFactory = new HlsMediaSource.Factory(dataSourceFactory); progressiveMediaSourceFactory = new ProgressiveMediaSource.Factory(dataSourceFactory); int alarmLength = PreferenceData.ALARM_LENGTH.getValue(this); for (int id = 0; id < alarmLength; id++) { alarms.add(new AlarmData(id, this)); } int timerLength = PreferenceData.TIMER_LENGTH.getValue(this); for (int id = 0; id < timerLength; id++) { TimerData timer = new TimerData(id, this); if (timer.isSet()) timers.add(timer); } if (timerLength > 0) startService(new Intent(this, TimerService.class)); SleepReminderService.refreshSleepTime(this); }
Example #19
Source File: MyActivity.java From googleads-ima-android with Apache License 2.0 | 5 votes |
private void initializePlayer() { // Create a SimpleExoPlayer and set is as the player for content and ads. player = new SimpleExoPlayer.Builder(this).build(); playerView.setPlayer(player); adsLoader.setPlayer(player); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, getString(R.string.app_name))); ProgressiveMediaSource.Factory mediaSourceFactory = new ProgressiveMediaSource.Factory(dataSourceFactory); // Create the MediaSource for the content you wish to play. MediaSource mediaSource = mediaSourceFactory.createMediaSource(Uri.parse(getString(R.string.content_url))); // Create the AdsMediaSource using the AdsLoader and the MediaSource. AdsMediaSource adsMediaSource = new AdsMediaSource(mediaSource, dataSourceFactory, adsLoader, playerView); // Prepare the content and ad to be played with the SimpleExoPlayer. player.prepare(adsMediaSource); // Set PlayWhenReady. If true, content and ads will autoplay. player.setPlayWhenReady(false); }
Example #20
Source File: ExoVideoView.java From ExoVideoView with Apache License 2.0 | 5 votes |
/** * Set the {@link SimpleExoPlayer} to use. * <p> * To transition a {@link SimpleExoPlayer} from targeting one view to another, it's recommended to * use {@link #switchTargetView(SimpleExoPlayer, ExoVideoView, ExoVideoView)} rather * than this method. If you do wish to use this method directly, be sure to attach the player to * the new view <em>before</em> calling {@code setPlayer(null)} to detach it from the old one. * This ordering is significantly more efficient and may allow for more seamless transitions. * * @param player The {@link SimpleExoPlayer} to use. */ public void setPlayer(SimpleExoPlayer player) { if (this.player == player) { return; } if (this.player != null) { this.player.removeListener(componentListener); this.player.removeTextOutput(componentListener); this.player.removeVideoListener(componentListener); if (surfaceView instanceof TextureView) { this.player.clearVideoTextureView((TextureView) surfaceView); } else if (surfaceView instanceof SurfaceView) { this.player.clearVideoSurfaceView((SurfaceView) surfaceView); } } this.player = player; if (useController) { controller.setPlayer(player); } if (shutterView != null) { shutterView.setVisibility(VISIBLE); } if (player != null) { if (surfaceView instanceof TextureView) { player.setVideoTextureView((TextureView) surfaceView); } else if (surfaceView instanceof SurfaceView) { player.setVideoSurfaceView((SurfaceView) surfaceView); } player.addVideoListener(componentListener); player.addTextOutput(componentListener); player.addListener(componentListener); maybeShowController(false); updateForCurrentTrackSelections(); } else { hideController(); hideArtwork(); } }
Example #21
Source File: ExoVideoView.java From ExoVideoView with Apache License 2.0 | 5 votes |
private void createExoPlayer(MediaSourceCreator creator) { if (player != null) { releasePlayer(); } DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(getContext()); renderersFactory.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); SimpleExoPlayer.Builder builder = new SimpleExoPlayer.Builder(getContext(), renderersFactory); TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(getContext(),new AdaptiveTrackSelection.Factory()); builder.setTrackSelector(new DefaultTrackSelector(getContext(),adaptiveTrackSelectionFactory)); builder.setTrackSelector(trackSelector); builder.setBandwidthMeter(new DefaultBandwidthMeter.Builder(getContext()).build()); SimpleExoPlayer internalPlayer = builder.build(); internalPlayer.addListener(componentListener); internalPlayer.addListener(creator.getEventLogger()); internalPlayer.addMetadataOutput(creator.getEventLogger()); setPlayer(internalPlayer); }
Example #22
Source File: ExoPlayerCreator.java From no-player with Apache License 2.0 | 5 votes |
@NonNull public SimpleExoPlayer create(DrmSessionCreator drmSessionCreator, DefaultDrmSessionEventListener drmSessionEventListener, MediaCodecSelector mediaCodecSelector, TrackSelector trackSelector) { DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = drmSessionCreator.create(drmSessionEventListener); SubtitleDecoderFactory subtitleDecoderFactory = new NoPlayerSubtitleDecoderFactory(); RenderersFactory renderersFactory = new SimpleRenderersFactory( context, EXTENSION_RENDERER_MODE_OFF, DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS, mediaCodecSelector, subtitleDecoderFactory ); DefaultLoadControl loadControl = new DefaultLoadControl(); return ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector, loadControl, drmSessionManager); }
Example #23
Source File: ExoPlayerFacade.java From no-player with Apache License 2.0 | 5 votes |
private void setMovieAudioAttributes(SimpleExoPlayer exoPlayer) { if (androidDeviceVersion.isLollipopTwentyOneOrAbove()) { AudioAttributes audioAttributes = new AudioAttributes.Builder() .setContentType(C.CONTENT_TYPE_MOVIE) .build(); exoPlayer.setAudioAttributes(audioAttributes); } }
Example #24
Source File: RendererTypeRequesterCreator.java From no-player with Apache License 2.0 | 5 votes |
RendererTypeRequester createfrom(final SimpleExoPlayer exoPlayer) { return new RendererTypeRequester() { @Override public int getRendererTypeFor(int index) { return exoPlayer.getRendererType(index); } }; }
Example #25
Source File: ExoPlayerVideoTrackSelector.java From no-player with Apache License 2.0 | 5 votes |
public Optional<PlayerVideoTrack> getSelectedVideoTrack(SimpleExoPlayer exoPlayer, RendererTypeRequester rendererTypeRequester, ContentType contentType) { Format selectedVideoFormat = exoPlayer.getVideoFormat(); if (selectedVideoFormat == null) { return Optional.absent(); } List<PlayerVideoTrack> videoTracks = getVideoTracks(rendererTypeRequester, contentType); return findSelectedVideoTrack(selectedVideoFormat, videoTracks); }
Example #26
Source File: SimpleExoPlayerView.java From K-Sonic with MIT License | 5 votes |
/** * Set the {@link SimpleExoPlayer} to use. The {@link SimpleExoPlayer#setTextOutput} and * {@link SimpleExoPlayer#setVideoListener} method of the player will be called and previous * assignments are overridden. * * @param player The {@link SimpleExoPlayer} to use. */ public void setPlayer(SimpleExoPlayer player) { if (this.player == player) { return; } if (this.player != null) { this.player.setTextOutput(null); this.player.setVideoListener(null); this.player.removeListener(componentListener); this.player.setVideoSurface(null); } this.player = player; if (useController) { controller.setPlayer(player); } if (shutterView != null) { shutterView.setVisibility(VISIBLE); } if (player != null) { if (surfaceView instanceof TextureView) { player.setVideoTextureView((TextureView) surfaceView); } else if (surfaceView instanceof SurfaceView) { player.setVideoSurfaceView((SurfaceView) surfaceView); } player.setVideoListener(componentListener); player.addListener(componentListener); player.setTextOutput(componentListener); maybeShowController(false); updateForCurrentTrackSelections(); } else { hideController(); hideArtwork(); } }
Example #27
Source File: ExoPlayerAdapter.java From leanback-showcase with Apache License 2.0 | 5 votes |
private void prepareMediaForPlaying() { reset(); if (mMediaSourceUri != null) { MediaSource mediaSource = onCreateMediaSource(mMediaSourceUri); mPlayer.prepare(mediaSource); } else { return; } mPlayer.setAudioStreamType(mAudioStreamType); mPlayer.setVideoListener(new SimpleExoPlayer.VideoListener() { @Override public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) { getCallback().onVideoSizeChanged(ExoPlayerAdapter.this, width, height); } @Override public void onRenderedFirstFrame() { } }); notifyBufferingStartEnd(); getCallback().onPlayStateChanged(ExoPlayerAdapter.this); }
Example #28
Source File: YouTubePlayerV2Fragment.java From SkyTube with GNU General Public License v3.0 | 5 votes |
private SimpleExoPlayer createExoPlayer() { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); Context context = getContext(); DefaultRenderersFactory defaultRenderersFactory = new DefaultRenderersFactory(context); return ExoPlayerFactory.newSimpleInstance(getContext(), defaultRenderersFactory, trackSelector, new DefaultLoadControl(), null, bandwidthMeter); }
Example #29
Source File: PlaybackSpeedController.java From SkyTube with GNU General Public License v3.0 | 5 votes |
public PlaybackSpeedController(Context context, TextView playbackSpeedTextView, SimpleExoPlayer player) { Utils.requireNonNull(playbackSpeedTextView, "playbackSpeedTextView"); Utils.requireNonNull(player, "SimpleExoPlayer"); this.player = player; this.playbackSpeedTextView = playbackSpeedTextView; this.playbackSpeedPopupMenu = new PopupMenu(context, playbackSpeedTextView); this.playbackSpeedTextView.setOnClickListener(this); }
Example #30
Source File: ExoPlayerView.java From react-native-video with MIT License | 5 votes |
/** * Set the {@link SimpleExoPlayer} to use. The {@link SimpleExoPlayer#setTextOutput} and * {@link SimpleExoPlayer#setVideoListener} method of the player will be called and previous * assignments are overridden. * * @param player The {@link SimpleExoPlayer} to use. */ public void setPlayer(SimpleExoPlayer player) { if (this.player == player) { return; } if (this.player != null) { this.player.setTextOutput(null); this.player.setVideoListener(null); this.player.removeListener(componentListener); this.player.setVideoSurface(null); } this.player = player; shutterView.setVisibility(VISIBLE); if (player != null) { setVideoView(); player.setVideoListener(componentListener); player.addListener(componentListener); player.setTextOutput(componentListener); } }