@Override public void onResume() { super.onResume(); mPlayer = ExoPlayer.Factory.newInstance(2, 1000, 5000); mPlayer.addListener(this); mPlayer.seekTo(mPlayerPosition); mMediaController.setMediaPlayer(new PlayerControl(mPlayer)); mMediaController.setEnabled(true); mCallback = new RendererBuilderCallback(); mBuilder.buildRenderers(mCallback); }
public DemoPlayer(RendererBuilder rendererBuilder) { this.rendererBuilder = rendererBuilder; player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000); player.addListener(this); playerControl = new PlayerControl(player); mainHandler = new Handler(); listeners = new CopyOnWriteArrayList<>(); lastReportedPlaybackState = STATE_IDLE; rendererBuildingState = RENDERER_BUILDING_STATE_IDLE; // Disable text initially. player.setSelectedTrack(TYPE_TEXT, TRACK_DISABLED); }
public EMExoPlayer(RenderBuilder rendererBuilder) { this.rendererBuilder = rendererBuilder; player = ExoPlayer.Factory.newInstance(RENDER_COUNT, BUFFER_LENGTH_MIN, REBUFFER_LENGTH_MIN); player.addListener(this); playerControl = new PlayerControl(player); mainHandler = new Handler(); listeners = new CopyOnWriteArrayList<>(); lastReportedPlaybackState = ExoPlayer.STATE_IDLE; rendererBuildingState = RenderBuildingState.IDLE; selectedTracks = new int[RENDER_COUNT]; // Disable text initially. selectedTracks[RENDER_CLOSED_CAPTION_INDEX] = DISABLED_TRACK; }
private void preparePlayer() { // TODO(cartland): Remove sample video. String url = "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/April%20Fool's%202013/Introducing%20Google%20Fiber%20to%20the%20Pole.mp4"; mVideo.setContentUrl(url); SampleSource sampleSource = new FrameworkSampleSource( this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT); // Build the track renderers videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource); // Setup the player player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000); player.addListener(this); // Build the player controls mediaController.setMediaPlayer(new PlayerControl(player)); mediaController.setEnabled(true); player.prepare(videoRenderer, audioRenderer); }
void initPlayer(String videoLink) { if (null == mExoPlayer) { mExoPlayer = ExoPlayer.Factory.newInstance(2); mPlayerControl = new PlayerControl(mExoPlayer); Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE); DataSource dataSource = new DefaultUriDataSource(this, null, USER_AGENT); ExtractorSampleSource sampleSource = new ExtractorSampleSource( Uri.parse(videoLink), dataSource, allocator, BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE); MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer( sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource); mExoPlayer.prepare(videoRenderer, audioRenderer); mExoPlayer.sendMessage( videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, mExoPlayerSurface.getHolder().getSurface()); mExoPlayer.setPlayWhenReady(true); } controllerBtn.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { mPlayerControl.pause(); } else { mPlayerControl.start(); } } }); mSeekBar.setMax(100); mSeekBar.setOnSeekBarChangeListener( new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { updateTime((long) (progress / 100.0f * mExoPlayer.getDuration())); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { controllerBtn.setChecked(true); timer.cancel(); } @Override public void onStopTrackingTouch(SeekBar seekBar) { mExoPlayer.seekTo((int) (mExoPlayer.getDuration() / 100.0f * seekBar.getProgress())); } }); mExoPlayer.addListener( new ExoPlayer.Listener() { @Override public void onPlayerStateChanged(boolean b, int i) { if (i == ExoPlayer.STATE_READY) { mProgress.setVisibility(View.INVISIBLE); timer = new Timer(true); timer.schedule( new TimerTask() { @Override public void run() { updateTime(mExoPlayer.getCurrentPosition()); updateSeekBar(); } }, 0, 1000); } } @Override public void onPlayWhenReadyCommitted() {} @Override public void onPlayerError(ExoPlaybackException e) {} }); }