private void setupExoPlayer() { TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); exoPlayer = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(this), new DefaultTrackSelector(adaptiveTrackSelectionFactory), new DefaultLoadControl()); pvVideoPreview.setPlayer(exoPlayer); exoPlayer.setPlayWhenReady(true); Uri uri = Uri.parse("asset:///sample_video.mp4"); MediaSource mediaSource = createMediaSource(this, uri); LoopingMediaSource loopingMediaSource = new LoopingMediaSource(mediaSource); exoPlayer.prepare(loopingMediaSource, true, false); }
private void initializePlayer() { if (player == null) { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, new DefaultLoadControl()); player.addListener(this); exoPlayerView.setPlayer(player); if (isTimelineStatic) { if (playerPosition == C.TIME_UNSET) { player.seekToDefaultPosition(playerWindow); } else { player.seekTo(playerWindow, playerPosition); } } audioBecomingNoisyReceiver.setListener(this); setPlayWhenReady(!isPaused); playerNeedsSource = true; } if (playerNeedsSource && srcUri != null) { MediaSource mediaSource = buildMediaSource(srcUri, extension); mediaSource = repeat ? new LoopingMediaSource(mediaSource) : mediaSource; player.prepare(mediaSource, !shouldRestorePosition, true); playerNeedsSource = false; eventEmitter.loadStart(); loadVideoStarted = true; } }
/*** * 获取视频数据源 * @return the media source */ MediaSource getMediaSource() { if (loopingCount > 0) { return new LoopingMediaSource(mediaSource, loopingCount); } return mediaSource; }
private MediaSource buildRepeatOneMediaSource(DataSource.Factory srcFactory, ExtractorsFactory extFactory) { if (mQueue.isEmpty()) { // We need to return an empty MediaSource (can't be null), so return a // ConcatenatingMediaSource with nothing to concatenate return new ConcatenatingMediaSource(); } Uri uri = mQueue.get(mQueueIndex).getLocation(); MediaSource source = new ExtractorMediaSource(uri, srcFactory, extFactory, null, null); return new LoopingMediaSource(source); }
private MediaSource buildRepeatAllMediaSource(DataSource.Factory sourceFactory, ExtractorsFactory extractorsFactory) { MediaSource queue = buildNoRepeatMediaSource(sourceFactory, extractorsFactory); return new LoopingMediaSource(queue); }
/** * Creates a loop source. The child source will be played multiple times. *Pass -1 to play it indefinitely. */ public Object CreateLoopSource (Object Source, int Count) { return new LoopingMediaSource((MediaSource) Source, Count > 0 ? Count : Integer.MAX_VALUE); }