/** * Switches the view targeted by a given {@link Player}. * * @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( Player player, @Nullable PlayerView oldPlayerView, @Nullable PlayerView 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); } }
/** * Releases the manager and the players that it holds. */ public void release() { currentItemIndex = C.INDEX_UNSET; mediaQueue.clear(); concatenatingMediaSource.clear(); castPlayer.setSessionAvailabilityListener(null); castPlayer.release(); localPlayerView.setPlayer(null); exoPlayer.release(); }
public void init(Context context, PlayerView playerView) { // Create a default track selector. TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // Create a player instance. player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); // Bind the player to the view. playerView.setPlayer(player); // This is the MediaSource representing the content media (i.e. not the ad). String contentUrl = context.getString(R.string.content_url); MediaSource contentMediaSource = buildMediaSource(Uri.parse(contentUrl)); // Compose the content media source into a new AdsMediaSource with both ads and content. MediaSource mediaSourceWithAds = new AdsMediaSource( contentMediaSource, /* adMediaSourceFactory= */ this, adsLoader, playerView.getOverlayFrameLayout()); // Prepare the player with the source. player.seekTo(contentPosition); player.prepare(mediaSourceWithAds); player.setPlayWhenReady(true); }
private PlayerManager( QueuePositionListener queuePositionListener, PlayerView localPlayerView, PlayerControlView castControlView, Context context, CastContext castContext) { this.queuePositionListener = queuePositionListener; this.localPlayerView = localPlayerView; this.castControlView = castControlView; mediaQueue = new ArrayList<>(); currentItemIndex = C.INDEX_UNSET; concatenatingMediaSource = new ConcatenatingMediaSource(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(); RenderersFactory renderersFactory = new DefaultRenderersFactory(context); exoPlayer = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector); exoPlayer.addListener(this); localPlayerView.setPlayer(exoPlayer); castPlayer = new CastPlayer(castContext); castPlayer.addListener(this); castPlayer.setSessionAvailabilityListener(this); castControlView.setPlayer(castPlayer); }
public void setView(PlayerView videoView) { videoView.setPlayer(player); }
@Override public void onServiceDisconnected(ComponentName componentName) { Log.d(TAG, "onServiceDisconnected"); simpleExoPlayerView.setPlayer(null); mBound = false; } };
@Override public void onServiceConnected(ComponentName className, IBinder service) { Log.d(TAG, "onServiceConnected"); VideoPlayerService.LocalBinder binder = (VideoPlayerService.LocalBinder) service; mService = binder.getService(); // 2. Create the player simpleExoPlayerView.setPlayer(mService.player); mBound = true; loadVideo(); }
public void destroyVideo() { simpleExoPlayerView.setPlayer(null); if (torrentStream != null) { torrentStream.stopStream(); } }
@Override protected void onStop() { playerView.setPlayer(null); player.release(); player = null; super.onStop(); } }
@Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); mPlayerView.setPlayer(null); }
public void setPlayer(SimpleExoPlayer player) { mPlayerView.setPlayer(player); mCropView.resetCropOverlayView(); }
@Override public void setPlayer(@Nullable Player player) { super.setPlayer(player); player.addListener(new ScreenDimmingVideoEventListener(this)); }
@Override protected void onStart() { super.onStart(); // Create a new Exo Player player = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector()); // Associate the ExoPlayer with the Player View playerView.setPlayer(player); // Build a DataSource.Factory capable of // loading http and local content DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory( this, Util.getUserAgent(this, getString(R.string.app_name))); // Specify the URI to play File file = new File(Environment.getExternalStorageDirectory(), // TODO Replace with a real file. "test2.mp4"); ExtractorMediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory) .createMediaSource(Uri.fromFile(file)); // Start loading the media source player.prepare(mediaSource); // Start playback automatically when ready player.setPlayWhenReady(true); }
player.setVideoSurfaceView(playerSurfaceView); playerView.setPlayer(player); playerView.setPlaybackPreparer(this);
simpleExoPlayerView.requestFocus(); simpleExoPlayerView.setPlayer(player);
private void initExoPlayer() { PlayerView playerView = findViewById(R.id.exoplayer_view); playerView.requestFocus(); playerView.setControllerAutoShow(false); playerView.setUseController(false); playerView.setKeepScreenOn(true); DefaultRenderersFactory rendererFactory = new DefaultRenderersFactory(this, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER); TrackSelector trackSelector = new DefaultTrackSelector(); DefaultLoadControl.Builder builder = new DefaultLoadControl.Builder(); builder.setAllocator(new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE)); builder.setBufferDurationsMs( 2000, 15000, 1500, 0 ); LoadControl loadControl = builder.createDefaultLoadControl(); player = ExoPlayerFactory.newSimpleInstance(this, rendererFactory, trackSelector, loadControl); player.addVideoListener(new com.google.android.exoplayer2.video.VideoListener() { @Override public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) { } @Override public void onRenderedFirstFrame() { mMPCheckTime = System.nanoTime(); } }); playerView.setPlayer(player); }