private MediaSource buildMediaSource(Uri uri, String overrideExtension) { int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension : uri.getLastPathSegment()); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null); case C.TYPE_DASH: return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null); case C.TYPE_HLS: return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, null); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_coutom3); ImaSdkSettings sdkSettings= ImaSdkFactory.getInstance().createImaSdkSettings(); sdkSettings.setLanguage("zh"); adsLoader = new ImaAdsLoader( this, Uri.parse(getString(R.string.ad_tag_url)),sdkSettings); mediaSourceBuilder=new MediaSourceBuilder(this,new DataSource(this.getApplication())); videoPlayerView = (VideoPlayerView) findViewById(R.id.exo_play_context_id); exoPlayerManager = new GestureVideoPlayer(this,mediaSourceBuilder,videoPlayerView ); exoPlayerManager.setTitle("视频标题"); exoPlayerManager.setExoPlayWatermarkImg(R.mipmap.watermark_big); MediaSource contentMediaSource =mediaSourceBuilder.initMediaSource( Uri.parse(getString(R.string.uri_test_6))); // Compose the content media source into a new AdsMediaSource with both ads and content. MediaSource mediaSourceWithAds = new AdsMediaSource(contentMediaSource, mediaSourceBuilder.getDataSource(), adsLoader, videoPlayerView.getPlayerView().getOverlayFrameLayout()); mediaSourceBuilder.setMediaSource(mediaSourceWithAds); Glide.with(this) .load(getString(R.string.uri_test_image)) .fitCenter() .placeholder(R.mipmap.test) .into(videoPlayerView.getPreviewImage()); }
public void preparePlayer() { MediaSource videoSource = new ExtractorMediaSource(syncplayuri, dataSourceFactory, extractorsFactory, null, null); mMediaPlayer.prepare(videoSource); mSyncPlayClient.setPlayerState(new syncPlayClientInterface.playerDetails() { @Override public long getPosition() { return mMediaPlayer.getCurrentPosition() / 1000L; } @Override public Boolean isPaused() { return !mMediaPlayer.getPlayWhenReady(); } }); }
private MediaSource buildMediaSource(Uri uri, String overrideExtension) { int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension : uri.getLastPathSegment()); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_DASH: return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_HLS: return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, eventLogger); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, eventLogger); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
private MediaSource buildMediaSource(Context context, Uri uri) { int type = getUrlType(uri.toString()); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, new DefaultDataSourceFactory(context, null, new DefaultHttpDataSourceFactory(USER_AGENT, null)), new DefaultSsChunkSource.Factory(new DefaultDataSourceFactory(context, BANDWIDTH_METER, new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER))), mainThreadHandler, null); case C.TYPE_DASH: return new DashMediaSource(uri, new DefaultDataSourceFactory(context, null, new DefaultHttpDataSourceFactory(USER_AGENT, null)), new DefaultDashChunkSource.Factory(new DefaultDataSourceFactory(context, BANDWIDTH_METER, new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER))), mainThreadHandler, null); case C.TYPE_HLS: return new HlsMediaSource(uri, new DefaultDataSourceFactory(context, BANDWIDTH_METER, new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER)), mainThreadHandler, null); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, new DefaultDataSourceFactory(context, BANDWIDTH_METER, new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER)), new DefaultExtractorsFactory(), mainThreadHandler, null); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
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 MediaSource buildMediaSource(Uri uri, String overrideExtension) { DataSource.Factory mediaDataSourceFactory = buildDataSourceFactory(true); int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri) : Util.inferContentType("." + overrideExtension); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null); case C.TYPE_DASH: return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null); case C.TYPE_HLS: return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, null); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
private void initializePlayer() { if (player == null) { // a factory to create an AdaptiveVideoTrackSelection TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); // using a DefaultTrackSelector with an adaptive video selection factory player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(adaptiveTrackSelectionFactory), new DefaultLoadControl()); player.addListener(componentListener); player.addVideoDebugListener(componentListener); player.addAudioDebugListener(componentListener); playerView.setPlayer(player); player.setPlayWhenReady(playWhenReady); player.seekTo(currentWindow, playbackPosition); } MediaSource mediaSource = buildMediaSource(Uri.parse(getString(R.string.media_url_dash))); player.prepare(mediaSource, true, false); }
private void initializePlayer(Uri videoUri){ if (mExoPlayer == null){ TrackSelector trackSelector = new DefaultTrackSelector(); LoadControl loadControl = new DefaultLoadControl(); mExoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); mExoPlayer.addListener(this); mExoPlayer.seekTo(currentPosition); mPlayerView.setPlayer(mExoPlayer); String userAgent = Util.getUserAgent(getContext(), "Tasty"); MediaSource mediaSource = new ExtractorMediaSource(videoUri, new DefaultDataSourceFactory( getContext(), userAgent), new DefaultExtractorsFactory(), null, null); mExoPlayer.prepare(mediaSource); if (playWhenReady) mExoPlayer.setPlayWhenReady(true); else mExoPlayer.setPlayWhenReady(false); } }
public MediaSource getMediaSource(boolean preview) { switch (streamType) { case C.TYPE_SS: return new SsMediaSource(uri, new DefaultDataSourceFactory(context, null, getHttpDataSourceFactory(preview)), new DefaultSsChunkSource.Factory(getDataSourceFactory(preview)), mainHandler, null); case C.TYPE_DASH: return new DashMediaSource(uri, new DefaultDataSourceFactory(context, null, getHttpDataSourceFactory(preview)), new DefaultDashChunkSource.Factory(getDataSourceFactory(preview)), mainHandler, null); case C.TYPE_HLS: return new HlsMediaSource(uri, getDataSourceFactory(preview), mainHandler, null); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, getDataSourceFactory(preview), new DefaultExtractorsFactory(), mainHandler, null); default: { throw new IllegalStateException("Unsupported type: " + streamType); } } }
@Override public void prepareAsync() throws IllegalStateException { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mInternalMediaPlayer = InternalExoPlayer.newInstance(mAppContext, trackSelector); mEventListener = new ExoEventListener(); mInternalMediaPlayer.addListener(mEventListener); mVideoListener = new ExoVideoListener(); mInternalMediaPlayer.addVideoListener(mVideoListener); MediaSource mediaSource = buildMediaSource(mUri, mHeaders); mInternalMediaPlayer.setVideoSurface(mSurface); mInternalMediaPlayer.prepare(mediaSource); notifyOnPrepared(); }
@Override public void startPlayer() { if(exoPlayer==null){ exoPlayer = ExoPlayerFactory.newSimpleInstance( context, new DefaultTrackSelector(), new DefaultLoadControl()); exoPlayer.addListener(this); } exoPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory( context, Util.getUserAgent(context, "uamp"), null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource mediaSource = new ExtractorMediaSource( Uri.parse(currentUrl), dataSourceFactory, extractorsFactory, null, null); exoPlayer.prepare(mediaSource); configPlayer(); }
private void setExoViewSource(@NonNull MasterSecret masterSecret, @NonNull VideoSlide videoSource) throws IOException { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); exoView.setPlayer(exoPlayer); DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null); AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(getContext(), masterSecret, defaultDataSourceFactory, null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource mediaSource = new ExtractorMediaSource(videoSource.getUri(), attachmentDataSourceFactory, extractorsFactory, null, null); exoPlayer.prepare(mediaSource); exoPlayer.setPlayWhenReady(true); }
public MediaPeriodHolder(Renderer[] renderers, RendererCapabilities[] rendererCapabilities, long rendererPositionOffsetUs, TrackSelector trackSelector, LoadControl loadControl, MediaSource mediaSource, Object periodUid, int periodIndex, boolean isLastPeriod, long startPositionUs) { this.renderers = renderers; this.rendererCapabilities = rendererCapabilities; this.rendererPositionOffsetUs = rendererPositionOffsetUs; this.trackSelector = trackSelector; this.loadControl = loadControl; this.mediaSource = mediaSource; this.uid = Assertions.checkNotNull(periodUid); this.index = periodIndex; this.isLast = isLastPeriod; this.startPositionUs = startPositionUs; sampleStreams = new SampleStream[renderers.length]; mayRetainStreamFlags = new boolean[renderers.length]; mediaPeriod = mediaSource.createPeriod(periodIndex, loadControl.getAllocator(), startPositionUs); }
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 initExoPlayer(MediaSource sampleSource) { if (exoPlayer == null) { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2. Create the player exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector); } exoPlayer.prepare(sampleSource); exoPlayer.setVideoSurfaceView(svPlayer); exoPlayer.setPlayWhenReady(true); initMediaControls(); }
protected MediaSource newMediaSource(Context context, String url, int type, Handler handler) { boolean hls = false; boolean localFile = url.startsWith("file://"); if (!localFile) { try { hls = type == MediaId.TYPE_VIDEO || Uri.parse(url).getPath().endsWith(".m3u8"); } catch (Exception ignore) { } } // expecting MP3 here ... otherwise HLS if ((localFile || type == MediaId.TYPE_AUDIO) && !hls) { return new ExtractorMediaSource(Uri.parse(url), buildDataSourceFactory(context, true, !localFile), new DefaultExtractorsFactory(), handler, this); } else { return new HlsMediaSource(Uri.parse(url), buildDataSourceFactory(context, true, true), handler, this); } }
/** * Makes sure the media player exists and has been reset. This will create * the media player if needed, or reset the existing media player if one * already exists. */ private void createMediaPlayer(String url, int type) { if (mMediaPlayer != null) { mMediaPlayer.release(); mMediaPlayer.removeListener(this); } mPrepared = false; mMediaPlayer = newMediaPlayer(mService.getApplicationContext(), url, type); mMediaPlayer.addListener(this); MediaSource mediaSource = newMediaSource(mService.getApplicationContext(), url, type, mHandler); mMediaPlayer.prepare(mediaSource); // Make sure the media player will acquire a wake-lock while // playing. If we don't do that, the CPU might go to sleep while the // song is playing, causing playback to stop. if (!mWakeLock.isHeld()) mWakeLock.acquire(); if (!mWifiLock.isHeld()) mWifiLock.acquire(); }
void loadVideo(SurfaceHolder surfaceHolder, DrmSessionCreator drmSessionCreator, Uri uri, ContentType contentType, ExoPlayerForwarder forwarder, MediaCodecSelector mediaCodecSelector) { this.contentType = contentType; exoPlayer = exoPlayerCreator.create(drmSessionCreator, forwarder.drmSessionEventListener(), mediaCodecSelector); rendererTypeRequester = rendererTypeRequesterCreator.createfrom(exoPlayer); exoPlayer.addListener(forwarder.exoPlayerEventListener()); exoPlayer.setVideoDebugListener(forwarder.videoRendererEventListener()); MediaSource mediaSource = mediaSourceFactory.create( contentType, uri, forwarder.extractorMediaSourceListener(), forwarder.mediaSourceEventListener() ); attachToSurface(surfaceHolder); exoPlayer.prepare(mediaSource, RESET_POSITION, DO_NOT_RESET_STATE); }
private MediaSource buildMediaSource(Uri uri, String overrideExtension) { int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension : uri.getLastPathSegment()); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), new DefaultSsChunkSource.Factory(mMediaDataSourceFactory), mMainHandler, mEventLogger); case C.TYPE_DASH: return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mMediaDataSourceFactory), mMainHandler, mEventLogger); case C.TYPE_HLS: return new HlsMediaSource(uri, mMediaDataSourceFactory, mMainHandler, mEventLogger); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, mMediaDataSourceFactory, new DefaultExtractorsFactory(), mMainHandler, mEventLogger); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
public void play(SimpleMediaSource source,boolean playWhenReady,long where){ if (player == null) { initSelfPlayer(); } setDisplayName(source.getDisplayName()); getFrameCover(source.getUrl()); MediaSource mediaSource = buildMediaSource(Uri.parse(source.getUrl()), null); player.setPlayWhenReady(requestAudioFocus() && playWhenReady); player.prepare(mediaSource); if (where == C.TIME_UNSET) { player.seekToDefaultPosition(); } else { player.seekTo(where); } }
private MediaSource buildMediaSource(Uri uri, String overrideExtension) { int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension : uri.getLastPathSegment()); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, new DefaultDataSourceFactory(context, userAgent), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_DASH: return new DashMediaSource(uri, new DefaultDataSourceFactory(context, userAgent), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_HLS: return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, eventLogger); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, eventLogger); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
private MediaSource buildMediaSource(Uri uri) { int type = Util.inferContentType(uri.getLastPathSegment()); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), new Handler(), null); case C.TYPE_DASH: return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), new Handler(), null); case C.TYPE_HLS: return new HlsMediaSource(uri, mediaDataSourceFactory, new Handler(), null); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), new Handler(), null); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
public void loadVideo(){ // CommonTools.showErrorLog("test"+"11111111111"); // CommonTools.showErrorLog("test"+playerPosition); if (player == null){ TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(mainHandler, videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, new DefaultLoadControl(), null, false); player.addListener(this); setPlayer(player); // CommonTools.showErrorLog("test"+"222222222"); if (playerPosition > 0){ // CommonTools.showErrorLog("test"+"3333333333"); player.seekTo(playerPosition); } player.setPlayWhenReady(isAutoPlay); } if (uri == null){ // CommonTools.showToast(getContext(), "请选择一个视频来播放"); return; } MediaSource mediaSource = buildMediaSource(uri, null); player.prepare(mediaSource); }
public HlsMediaPeriod(Uri manifestUri, DataSource.Factory dataSourceFactory, int minLoadableRetryCount, EventDispatcher eventDispatcher, MediaSource.Listener sourceListener, Allocator allocator, long positionUs) { this.manifestUri = manifestUri; this.dataSourceFactory = dataSourceFactory; this.minLoadableRetryCount = minLoadableRetryCount; this.eventDispatcher = eventDispatcher; this.sourceListener = sourceListener; this.allocator = allocator; streamWrapperIndices = new IdentityHashMap<>(); timestampAdjusterProvider = new TimestampAdjusterProvider(); manifestParser = new HlsPlaylistParser(); continueLoadingHandler = new Handler(); manifestFetcher = new Loader("Loader:ManifestFetcher"); preparePositionUs = positionUs; continueLoadingRunnable = new Runnable() { @Override public void run() { callback.onContinueLoadingRequested(HlsMediaPeriod.this); } }; }
@Override protected MediaSource[] doInBackground(MediaFile... media) { try { browser = Browser.getInstance(Config.mountDirectory); DataSource.Factory dataSourceFactory = new NfsDataSourceFactory(browser.getContext()); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource videoSource = new ExtractorMediaSource(Uri.parse("nfs://host/" + media[0].getPath()), dataSourceFactory, extractorsFactory, null, null); if (media[0].getSubtitlePath() != null) { Format subtitleFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP, null, Format.NO_VALUE, Format.NO_VALUE, "en", null); MediaSource subtitleSource = new SingleSampleMediaSource(Uri.parse("nfs://host/" + media[0].getSubtitlePath()), dataSourceFactory, subtitleFormat, Long.MAX_VALUE, 0); return new MediaSource[]{videoSource, subtitleSource}; } else return new MediaSource[]{videoSource}; } catch (IOException e) { e.printStackTrace(); } return null; }
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); }
@Test public void toggle_toPlay_playsSource() { String id = "id"; String url = "url"; PlaybackSource playbackSource = new PlaybackSource(new Id(id), url); new ArrangeBuilder() .withIdleExoPlayer() .withMediaSource() .act() .init(); exoPlayerAudioPlayer.togglePlayback(playbackSource); verify(mediaSourceFactory).create(url); verify(exoPlayer).prepare(any(MediaSource.class)); verify(exoPlayer).setPlayWhenReady(true); }
@Test public void toggle_withNewUrl_playsNewSource_whenPlaying() { String id1 = "id1"; String id2 = "id2"; String url1 = "url1"; String url2 = "url2"; PlaybackSource playbackSource1 = new PlaybackSource(new Id(id1), url1); PlaybackSource playbackSource2 = new PlaybackSource(new Id(id2), url2); ArrangeBuilder arrangeBuilder = new ArrangeBuilder() .withIdleExoPlayer() .withMediaSource(); arrangeBuilder.act() .init() .togglePlayback(playbackSource1); arrangeBuilder.withPlayingExoPlayer(); exoPlayerAudioPlayer.togglePlayback(playbackSource2); InOrder inOrder = inOrder(exoPlayer, mediaSourceFactory); inOrder.verify(mediaSourceFactory).create(url1); inOrder.verify(exoPlayer).prepare(any(MediaSource.class)); inOrder.verify(exoPlayer).setPlayWhenReady(true); inOrder.verify(mediaSourceFactory).create(url2); inOrder.verify(exoPlayer).prepare(any(MediaSource.class)); inOrder.verify(exoPlayer).setPlayWhenReady(true); }
@Test public void toggle_withNewUrl_playsNewSource_whenEnded() { String id1 = "id1"; String id2 = "id2"; String url1 = "url1"; String url2 = "url2"; PlaybackSource playbackSource1 = new PlaybackSource(new Id(id1), url1); PlaybackSource playbackSource2 = new PlaybackSource(new Id(id2), url2); ArrangeBuilder arrangeBuilder = new ArrangeBuilder() .withIdleExoPlayer() .withMediaSource(); arrangeBuilder.act() .init() .togglePlayback(playbackSource1); arrangeBuilder.withEndedExoPlayer(); exoPlayerAudioPlayer.togglePlayback(playbackSource2); InOrder inOrder = inOrder(exoPlayer, mediaSourceFactory); inOrder.verify(mediaSourceFactory).create(url1); inOrder.verify(exoPlayer).prepare(any(MediaSource.class)); inOrder.verify(exoPlayer).setPlayWhenReady(true); inOrder.verify(mediaSourceFactory).create(url2); inOrder.verify(exoPlayer).prepare(any(MediaSource.class)); inOrder.verify(exoPlayer).setPlayWhenReady(true); }
private void initializePlayer() { simpleExoPlayerView.requestFocus(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); simpleExoPlayerView.setPlayer(player); MediaSource[] mediaSources = new MediaSource[videos.size()]; for (int i = 0; i < videos.size(); i++) { mediaSources[i] = buildMediaSource(Uri.parse(videos.get(i).videoUrl)); } MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources); player.prepare(mediaSource); }