use of com.google.android.exoplayer2.RenderersFactory in project Camera-Roll-Android-App by kollerlukas.
the class VideoPlayerActivity method initPlayer.
private void initPlayer() {
// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, getString(R.string.app_name)), null);
// Produces Extractor instances for parsing the media data.
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
// This is the MediaSource representing the media to be played.
MediaSource videoSource = new ExtractorMediaSource(videoUri, dataSourceFactory, extractorsFactory, null, null);
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this);
// Create the player
player = ExoPlayerFactory.newSimpleInstance(renderersFactory, new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(null)), new DefaultLoadControl());
// Bind the player to the view.
SimpleExoPlayerView simpleExoPlayerView = findViewById(R.id.simpleExoPlayerView);
simpleExoPlayerView.setPlayer(player);
// Prepare the player with the source.
player.prepare(videoSource);
player.setRepeatMode(Player.REPEAT_MODE_ONE);
player.setPlayWhenReady(true);
final ImageButton playPause = findViewById(R.id.play_pause);
player.addListener(new SimpleEventListener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
// update PlayPause-Button
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && showAnimations()) {
if (player.getPlayWhenReady()) {
playPause.setImageResource(R.drawable.play_to_pause_avd);
} else {
playPause.setImageResource(R.drawable.pause_to_play_avd);
}
Drawable d = playPause.getDrawable();
if (d instanceof Animatable) {
((Animatable) d).start();
}
} else {
if (player.getPlayWhenReady()) {
playPause.setImageResource(R.drawable.ic_pause_white);
} else {
playPause.setImageResource(R.drawable.ic_play_arrow_white);
}
}
}
});
}
use of com.google.android.exoplayer2.RenderersFactory in project ExoPlayer by google.
the class ExoHostedTest method buildExoPlayer.
protected ExoPlayer buildExoPlayer(HostActivity host, Surface surface, MappingTrackSelector trackSelector) {
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(host);
renderersFactory.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF);
renderersFactory.setAllowedVideoJoiningTimeMs(/* allowedVideoJoiningTimeMs= */
0);
ExoPlayer player = new ExoPlayer.Builder(host, renderersFactory).setTrackSelector(trackSelector).build();
player.setVideoSurface(surface);
return player;
}
use of com.google.android.exoplayer2.RenderersFactory in project ExoPlayer by google.
the class DefaultAnalyticsCollectorTest method onPlayerError_thrownDuringRendererReplaceStreamAtPeriodTransition_isReportedForNewPeriod.
@Test
public void onPlayerError_thrownDuringRendererReplaceStreamAtPeriodTransition_isReportedForNewPeriod() throws Exception {
FakeMediaSource source = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.AUDIO_FORMAT);
RenderersFactory renderersFactory = (eventHandler, videoListener, audioListener, textOutput, metadataOutput) -> new Renderer[] { new FakeRenderer(C.TRACK_TYPE_AUDIO) {
private int streamChangeCount = 0;
@Override
protected void onStreamChanged(Format[] formats, long startPositionUs, long offsetUs) throws ExoPlaybackException {
// period transition (as the first time is when enabling the stream initially).
if (++streamChangeCount == 2) {
throw createRendererException(new IllegalStateException(), ExoPlayerTestRunner.AUDIO_FORMAT, PlaybackException.ERROR_CODE_UNSPECIFIED);
}
}
} };
TestAnalyticsListener listener = runAnalyticsTest(new ConcatenatingMediaSource(source, source), /* actionSchedule= */
null, renderersFactory);
populateEventIds(listener.lastReportedTimeline);
assertThat(listener.getEvents(EVENT_PLAYER_ERROR)).containsExactly(period1);
}
use of com.google.android.exoplayer2.RenderersFactory in project ExoPlayer by google.
the class DefaultAnalyticsCollectorTest method onPlayerError_thrownDuringRendererEnableAtPeriodTransition_isReportedForNewPeriod.
@Test
public void onPlayerError_thrownDuringRendererEnableAtPeriodTransition_isReportedForNewPeriod() throws Exception {
FakeMediaSource source0 = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT);
FakeMediaSource source1 = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.AUDIO_FORMAT);
RenderersFactory renderersFactory = (eventHandler, videoListener, audioListener, textOutput, metadataOutput) -> new Renderer[] { new FakeRenderer(C.TRACK_TYPE_VIDEO), new FakeRenderer(C.TRACK_TYPE_AUDIO) {
@Override
protected void onEnabled(boolean joining, boolean mayRenderStartOfStream) throws ExoPlaybackException {
// Fail when enabling the renderer. This will happen during the period transition.
throw createRendererException(new IllegalStateException(), ExoPlayerTestRunner.AUDIO_FORMAT, PlaybackException.ERROR_CODE_UNSPECIFIED);
}
} };
TestAnalyticsListener listener = runAnalyticsTest(new ConcatenatingMediaSource(source0, source1), /* actionSchedule= */
null, renderersFactory);
populateEventIds(listener.lastReportedTimeline);
assertThat(listener.getEvents(EVENT_PLAYER_ERROR)).containsExactly(period1);
}
use of com.google.android.exoplayer2.RenderersFactory in project ExoPlayer by google.
the class DefaultAnalyticsCollectorTest method runAnalyticsTest.
private static TestAnalyticsListener runAnalyticsTest(MediaSource mediaSource, @Nullable ActionSchedule actionSchedule, RenderersFactory renderersFactory) throws Exception {
Surface surface = new Surface(new SurfaceTexture(/* texName= */
0));
TestAnalyticsListener listener = new TestAnalyticsListener();
try {
new ExoPlayerTestRunner.Builder(ApplicationProvider.getApplicationContext()).setMediaSources(mediaSource).setRenderersFactory(renderersFactory).setVideoSurface(surface).setAnalyticsListener(listener).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
} catch (ExoPlaybackException e) {
// Ignore ExoPlaybackException as these may be expected.
} finally {
surface.release();
}
return listener;
}
Aggregations