/** * 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) { 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); } }
/*** * 创建实例播放实例,并不开始缓冲 **/ private SimpleExoPlayer createFullPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); BufferingLoadControl loadControl = new BufferingLoadControl(); if (null == modelType) { setDefaultLoadModel(); } else { loadControl.setListener(new LoadListener() { @Override public void onProgress(long pro) { getPlayerViewListener().showNetSpeed(String.valueOf(pro) + "%"); } }); } DefaultRenderersFactory rf = new DefaultRenderersFactory(activity, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(rf, trackSelector, loadControl); player.setPlaybackParameters(playbackParameters); getPlayerViewListener().setPlayer(player); return player; }
/** * 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 SimpleExoPlayerView oldPlayerView, @Nullable SimpleExoPlayerView 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); } }
@Override public IBinder onBind(final Intent intent) { bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "SyncPlayer"), bandwidthMeter); extractorsFactory = new DefaultExtractorsFactory(); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl); mMediaPlayer = player; setCompletionListener(); nbuilder.setSmallIcon(R.mipmap.ic_launcher); return mBinder; }
public void setPlayer(SimpleExoPlayer player) { if (this.player == player) { return; } if (this.player != null) { this.player.removeListener(this); } this.player = player; if (player != null) { player.addListener(this); boolean playing = player.getPlayWhenReady(); setIsPlaying(playing); } updateAll(); }
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; } } } }
/** * 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); } }
@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); } }
public SimpleExoPlayer prepareExoPlayerForUri( int playerKey, @NonNull Context context, @NonNull Uri uri, @NonNull SimpleExoPlayerView simpleExoPlayerView, int currentWindow, boolean playWhenReady, long playbackPosition) { SimpleExoPlayer simpleExoPlayer = playersInUse.get(playerKey); if (simpleExoPlayer == null) { simpleExoPlayer = setUpMediaPlayer(context); simpleExoPlayerView.setPlayer(simpleExoPlayer); simpleExoPlayer.setPlayWhenReady(playWhenReady); simpleExoPlayer.seekTo(currentWindow, playbackPosition); MediaSource mediaSource = setUpMediaSource(context, uri); simpleExoPlayer.prepare(mediaSource, true, false); playersInUse.put(playerKey, simpleExoPlayer); } else { simpleExoPlayer.seekTo(currentWindow, playbackPosition); simpleExoPlayer.setPlayWhenReady(playWhenReady); } return simpleExoPlayer; }
private SimpleExoPlayer setupPlayer(){ Log.d(TAG,"Setting up Player."); videoView.setKeepScreenOn(true); mUserAgent = Util.getUserAgent(getContext(), getResources().getString(R.string.app_name)); AdaptiveTrackSelection.Factory trackSelectorFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectorFactory); LoadControl loadControl = new DefaultLoadControl(); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(getContext(), null, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); exoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl); MyListener listener = new MyListener(exoPlayer, this); exoPlayer.addVideoListener(listener); exoPlayer.addListener(listener); exoPlayer.setPlayWhenReady(mPlaybackState); exoPlayer.prepare(buildMediaSource(Uri.parse(mRecording.getRecordingUrl()),"")); return exoPlayer; }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); Uri uri = intent.getParcelableExtra("uri"); long playerPosition = intent.getLongExtra("position", C.TIME_UNSET); int playerWindow = intent.getIntExtra("windowIndex", 0); boolean rotation = intent.getBooleanExtra("rotation", false); if (rotation) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } playerInstance = ExoPlayerInstance.getInstance(); SimpleExoPlayer player = playerInstance.getPlayer(); setContentView(R.layout.activity_video_player); playerView = (SimpleExoPlayerView) findViewById(R.id.player_view); playerView.setPlayer(player); if (playerPosition == C.TIME_UNSET) { player.seekToDefaultPosition(playerWindow); } else { player.seekTo(playerWindow, playerPosition); } playerInstance.prepare(uri, null); setVolumeControlStream(AudioManager.STREAM_MUSIC); }
@NonNull public SimpleExoPlayer create(DrmSessionCreator drmSessionCreator, DefaultDrmSessionManager.EventListener drmSessionEventListener, MediaCodecSelector mediaCodecSelector) { DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = drmSessionCreator.create(drmSessionEventListener); RenderersFactory renderersFactory = new SimpleRenderersFactory( context, drmSessionManager, EXTENSION_RENDERER_MODE_OFF, DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS, mediaCodecSelector ); DefaultLoadControl loadControl = new DefaultLoadControl(); return ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl); }
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); }
/** * Builds an instance. Note that the {@code PlayerAdapter} does not manage the lifecycle of the * {@link SimpleExoPlayer} instance. The caller remains responsible for releasing the player when * it's no longer required. * * @param context The current context (activity). * @param player Instance of your exoplayer that needs to be configured. * @param updatePeriodMs The delay between player control updates, in milliseconds. */ public LeanbackPlayerAdapter(Context context, SimpleExoPlayer player, final int updatePeriodMs) { this.context = context; this.player = player; handler = new Handler(); componentListener = new ComponentListener(); controlDispatcher = new DefaultControlDispatcher(); updateProgressRunnable = new Runnable() { @Override public void run() { Callback callback = getCallback(); callback.onCurrentPositionChanged(LeanbackPlayerAdapter.this); callback.onBufferedPositionChanged(LeanbackPlayerAdapter.this); handler.postDelayed(this, updatePeriodMs); } }; }
@Override protected void doActionAndScheduleNextImpl(final SimpleExoPlayer player, final MappingTrackSelector trackSelector, final Surface surface, final Handler handler, final ActionNode nextAction) { if (nextAction == null) { return; } Player.EventListener listener = new Player.DefaultEventListener() { @Override public void onTimelineChanged(Timeline timeline, Object manifest) { if (timeline.equals(expectedTimeline)) { player.removeListener(this); nextAction.schedule(player, trackSelector, surface, handler); } } }; player.addListener(listener); if (player.getCurrentTimeline().equals(expectedTimeline)) { player.removeListener(listener); nextAction.schedule(player, trackSelector, surface, handler); } }
@Override protected void doActionAndScheduleNextImpl(final SimpleExoPlayer player, final MappingTrackSelector trackSelector, final Surface surface, final Handler handler, final ActionNode nextAction) { if (nextAction == null) { return; } if (targetPlaybackState == player.getPlaybackState()) { nextAction.schedule(player, trackSelector, surface, handler); } else { player.addListener(new Player.DefaultEventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (targetPlaybackState == playbackState) { player.removeListener(this); nextAction.schedule(player, trackSelector, surface, handler); } } }); } }
/** * 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, SimpleExoPlayerView, SimpleExoPlayerView)} 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(); } }
private static SimpleExoPlayer createPlayer(Context context) { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); return ExoPlayerFactory.newSimpleInstance(context.getApplicationContext(), trackSelector); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (!isPlaying) { Handler mainHandler = new Handler(); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(MainActivity.this, trackSelector, loadControl); SimpleExoPlayerView playerView = (SimpleExoPlayerView) findViewById(R.id.videoView); playerView.setPlayer(player); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(MainActivity.this, Util.getUserAgent(MainActivity.this, "yourApplicationName")); MediaSource mediaSource = new ExtractorMediaSource(Uri.parse("https://r7---sn-3c27ln7k.googlevideo.com/videoplayback?id=6fb497d0971b8cdf&itag=22&source=picasa&begin=0&requiressl=yes&mm=30&mn=sn-3c27ln7k&ms=nxu&mv=m&nh=IgphcjAzLmticDAxKgkxMjcuMC4wLjE&pl=22&sc=yes&mime=video/mp4&lmt=1486083166327499&mt=1486135406&ip=134.249.158.189&ipbits=8&expire=1486164239&sparams=ip,ipbits,expire,id,itag,source,requiressl,mm,mn,ms,mv,nh,pl,sc,mime,lmt&signature=3BB06D8D4294F8C49B3CE910B3D6849954302BB1.02ABE00700DFCEF715E72D0EFB73B67841E659F8&key=ck2&ratebypass=yes&title=%5BAnime365%5D%20Kuzu%20no%20Honkai%20-%2004%20(t1174045)"), dataSourceFactory, new DefaultExtractorsFactory(), null, null); player.prepare(mediaSource); player.setPlayWhenReady(true); } }
/** * 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. * <p> * @param player The {@link SimpleExoPlayer} to use. */ public void setPlayer(SimpleExoPlayer player, @NonNull TubiPlaybackInterface playbackInterface) { setPlaybackInterface(playbackInterface); if (this.player == player) { return; } if (this.player != null) { this.player.removeListener(componentListener); this.player.clearTextOutput(componentListener); this.player.clearVideoListener(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,this, playbackInterface); } 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.setTextOutput(componentListener); player.addListener(componentListener); // maybeShowController(false); updateForCurrentTrackSelections(); } else { hideController(); hideArtwork(); } }
public void setPlayer(@NonNull SimpleExoPlayer player, @NonNull final TubiPlaybackControlInterface playbackControlInterface, @NonNull final TubiPlaybackInterface playbackInterface) { if (this.mPlayer == null || this.mPlayer != player) { tubiObservable = new TubiObservable(player, playbackControlInterface, playbackInterface); //Controller doesn't get re-initialized TODO fix instance call mBinding.viewTubiControllerSubtitlesIb.clearClickListeners(); mBinding.viewTubiControllerQualityIb.clearClickListeners(); mBinding.viewTubiControllerChromecastIb.clearClickListeners(); mBinding.viewTubiControllerPlayToggleIb.clearClickListeners(); mBinding.setPlayMedia(tubiObservable); } }
public TubiObservable(@NonNull SimpleExoPlayer player, @NonNull final TubiPlaybackControlInterface playbackControlInterface, @NonNull final TubiPlaybackInterface playbackInterface) { this.playbackControlInterface = playbackControlInterface; this.playbackInterface = playbackInterface; setPlayer(player); setAdPlaying(false); }
private void stopAdandPlayerMovie(PlayerUIController controller, PlayerComponentController componentController, MediaModel movieMedia) { SimpleExoPlayer adPlayer = controller.getAdPlayer(); SimpleExoPlayer moviePlayer = controller.getContentPlayer(); //first remove the AdPlayer's listener and pause the player adPlayer.removeListener(componentController.getAdPlayingMonitor()); adPlayer.setPlayWhenReady(false); //then update the playerView with SimpleExoPlayer and Movie MediaModel TubiExoPlayerView tubiExoPlayerView = (TubiExoPlayerView) controller.getExoPlayerView(); tubiExoPlayerView.setPlayer(moviePlayer, componentController.getTubiPlaybackInterface()); tubiExoPlayerView.setMediaModel(movieMedia, false); //prepare the moviePlayer with data source and set it play boolean haveResumePosition = controller.getMovieResumePosition() != C.TIME_UNSET; if (moviePlayer.getPlaybackState() == ExoPlayer.STATE_IDLE) { moviePlayer.prepare(movieMedia.getMediaSource(), !haveResumePosition, false); } updatePlayerPosition(moviePlayer, controller); moviePlayer.setPlayWhenReady(true); hideVpaidNShowPlayer(controller); }
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()); } }
@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; }
@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; }
public void clearAllPlayers() { Collection<SimpleExoPlayer> players = playersInUse.values(); for (SimpleExoPlayer player : players) { player.release(); } playersInUse.clear(); }
public PlayerView(Context context, SimpleExoPlayer player) { super(context); simpleExoPlayerView = new SimpleExoPlayerView(context); progressBar = new ProgressBar(context); textView = new TextView(context); textView.setX(40); textView.setY(20); textView.setTextColor(Color.parseColor("#FFFFFF")); textView.setTextSize(16); textView.setText("By Herudi"); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100); params.addRule(RelativeLayout.CENTER_IN_PARENT); simpleExoPlayerView.setLayoutParams(new SimpleExoPlayerView.LayoutParams( SimpleExoPlayerView.LayoutParams.MATCH_PARENT, SimpleExoPlayerView.LayoutParams.MATCH_PARENT )); setLayoutParams(new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT )); setBackgroundColor(ContextCompat.getColor(context, android.R.color.black)); addView(simpleExoPlayerView); addView(textView); addView(progressBar,params); simpleExoPlayerView.setUseController(true); simpleExoPlayerView.requestFocus(); simpleExoPlayerView.setPlayer(player); simpleExoPlayerView.setControllerVisibilityListener(new PlaybackControlView.VisibilityListener() { @Override public void onVisibilityChange(int visibility) { if (visibility==0){ textView.setVisibility(VISIBLE); }else { textView.setVisibility(GONE); } } }); }
private SimpleExoPlayer createFullPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(playerView.getContext()), trackSelector, loadControl); player.setPlayWhenReady(true); player.prepare(mediaSourceBuilder.getMediaSource(false)); player.addListener(eventListener); return player; }
private SimpleExoPlayer createFullPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(playerView.getContext()), trackSelector, loadControl); player.setPlayWhenReady(true); player.prepare(mediaSourceBuilder.getMediaSource(false)); player.addListener(this); return player; }
private SimpleExoPlayer createPreviewPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new WorstVideoTrackSelection.Factory(); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new PreviewLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(playerView.getContext()), trackSelector, loadControl); player.setPlayWhenReady(false); player.setVolume(0f); player.prepare(mediaSourceBuilder.getMediaSource(true)); return player; }
private View.OnClickListener onPictureInPictureClick() { return view -> { if (exoPlayer != null && exoPlayer.getPlaybackState() == SimpleExoPlayer.STATE_READY) { int videoWidth = exoPlayer.getVideoFormat().width; int videoHeight = exoPlayer.getVideoFormat().height; PictureInPictureParams params = new PictureInPictureParams.Builder() .setAspectRatio(new Rational(videoWidth, videoHeight)) .build(); enterPictureInPictureMode(params); } else { Toast.makeText(PictureInPictureActivity.this, R.string.video_playback_not_ready, Toast.LENGTH_SHORT).show(); } }; }
@Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playWhenReady && playbackState == SimpleExoPlayer.STATE_READY) { Timber.d("media player rendering start"); listener.onBufferingEnded(); } }
public void resume() { if (player.getPlaybackState() == SimpleExoPlayer.STATE_IDLE) { player.prepare(videoSource); player.seekTo(millis); player.setPlayWhenReady(true); } }
RendererTypeRequester createfrom(final SimpleExoPlayer exoPlayer) { return new RendererTypeRequester() { @Override public int getRendererTypeFor(int index) { return exoPlayer.getRendererType(index); } }; }
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); }
private void setPlayer(SimpleExoPlayer player, boolean isFromSelf) { if (this.player == player && !isFromSelf) { return; } if (this.player != null) { this.player.removeListener(componentListener); this.player.setVideoSurface(null); } this.player = player; if (useController) { controller.setPlayer(player); } 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); } else { shutterView.setVisibility(VISIBLE); controller.hide(); } }
/** * 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(); } }