Search in sources :

Example 1 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.

the class ExoPlayerTest method testPlaySinglePeriodTimeline.

/**
   * Tests playback of a source that exposes a single period.
   */
public void testPlaySinglePeriodTimeline() throws Exception {
    PlayerWrapper playerWrapper = new PlayerWrapper();
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(false, false, 0));
    Object manifest = new Object();
    MediaSource mediaSource = new FakeMediaSource(timeline, manifest, TEST_VIDEO_FORMAT);
    FakeRenderer renderer = new FakeRenderer(TEST_VIDEO_FORMAT);
    playerWrapper.setup(mediaSource, renderer);
    playerWrapper.blockUntilEnded(TIMEOUT_MS);
    assertEquals(0, playerWrapper.positionDiscontinuityCount);
    assertEquals(1, renderer.formatReadCount);
    assertEquals(1, renderer.bufferReadCount);
    assertTrue(renderer.isEnded);
    assertEquals(timeline, playerWrapper.timeline);
    assertEquals(manifest, playerWrapper.manifest);
    assertEquals(new TrackGroupArray(new TrackGroup(TEST_VIDEO_FORMAT)), playerWrapper.trackGroups);
}
Also used : MediaSource(com.google.android.exoplayer2.source.MediaSource) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray)

Example 2 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.

the class ExoPlayerTest method testReadAheadToEndDoesNotResetRenderer.

/**
   * Tests that the player does not unnecessarily reset renderers when playing a multi-period
   * source.
   */
public void testReadAheadToEndDoesNotResetRenderer() throws Exception {
    final PlayerWrapper playerWrapper = new PlayerWrapper();
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(false, false, 10), new TimelineWindowDefinition(false, false, 10), new TimelineWindowDefinition(false, false, 10));
    MediaSource mediaSource = new FakeMediaSource(timeline, null, TEST_VIDEO_FORMAT, TEST_AUDIO_FORMAT);
    FakeRenderer videoRenderer = new FakeRenderer(TEST_VIDEO_FORMAT);
    FakeMediaClockRenderer audioRenderer = new FakeMediaClockRenderer(TEST_AUDIO_FORMAT) {

        @Override
        public long getPositionUs() {
            // TODO: Avoid hard-coding ExoPlayerImplInternal.RENDERER_TIMESTAMP_OFFSET_US.
            return isCurrentStreamFinal() ? 60000030 : 60000000;
        }

        @Override
        public boolean isEnded() {
            // Allow playback to end once the final period is playing.
            return playerWrapper.positionDiscontinuityCount == 2;
        }
    };
    playerWrapper.setup(mediaSource, videoRenderer, audioRenderer);
    playerWrapper.blockUntilEnded(TIMEOUT_MS);
    assertEquals(2, playerWrapper.positionDiscontinuityCount);
    assertEquals(1, audioRenderer.positionResetCount);
    assertTrue(videoRenderer.isEnded);
    assertTrue(audioRenderer.isEnded);
    assertEquals(timeline, playerWrapper.timeline);
    assertNull(playerWrapper.manifest);
}
Also used : MediaSource(com.google.android.exoplayer2.source.MediaSource)

Example 3 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.

the class ExoPlayerImplInternal method sendMessagesInternal.

private void sendMessagesInternal(ExoPlayerMessage[] messages) throws ExoPlaybackException {
    try {
        for (ExoPlayerMessage message : messages) {
            message.target.handleMessage(message.messageType, message.message);
        }
        if (mediaSource != null) {
            // The message may have caused something to change that now requires us to do work.
            handler.sendEmptyMessage(MSG_DO_SOME_WORK);
        }
    } finally {
        synchronized (this) {
            customMessagesProcessed++;
            notifyAll();
        }
    }
}
Also used : ExoPlayerMessage(com.google.android.exoplayer2.ExoPlayer.ExoPlayerMessage)

Example 4 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.

the class DashMediaSource method prepareSource.

// MediaSource implementation.
@Override
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
    sourceListener = listener;
    if (sideloadedManifest) {
        loaderErrorThrower = new LoaderErrorThrower.Dummy();
        processManifest(false);
    } else {
        dataSource = manifestDataSourceFactory.createDataSource();
        loader = new Loader("Loader:DashMediaSource");
        loaderErrorThrower = loader;
        handler = new Handler();
        startLoadingManifest();
    }
}
Also used : LoaderErrorThrower(com.google.android.exoplayer2.upstream.LoaderErrorThrower) Loader(com.google.android.exoplayer2.upstream.Loader) Handler(android.os.Handler)

Example 5 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource in project RandomWebm by alkocher.

the class RandomFragment method initPlayer.

private void initPlayer(String VIDEO_URL) {
    playerView.setPlayer(player);
    MediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(VIDEO_URL));
    player.prepare(mediaSource);
    player.setPlayWhenReady(true);
    // Progress bar
    player.addListener(new ExoPlayer.EventListener() {

        @Override
        public void onTimelineChanged(Timeline timeline, Object manifest) {
        }

        @Override
        public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
        }

        @Override
        public void onLoadingChanged(boolean isLoading) {
        }

        @Override
        public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
            if (playbackState == ExoPlayer.STATE_BUFFERING) {
                progressBar.setVisibility(View.VISIBLE);
            } else {
                progressBar.setVisibility(View.GONE);
            }
        }

        @Override
        public void onRepeatModeChanged(int repeatMode) {
        }

        @Override
        public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
        }

        @Override
        public void onPlayerError(ExoPlaybackException error) {
        }

        @Override
        public void onPositionDiscontinuity(int reason) {
        }

        @Override
        public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
        }

        @Override
        public void onSeekProcessed() {
        }
    });
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) SimpleExoPlayer(com.google.android.exoplayer2.SimpleExoPlayer) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) TrackSelectionArray(com.google.android.exoplayer2.trackselection.TrackSelectionArray) Timeline(com.google.android.exoplayer2.Timeline) MediaSource(com.google.android.exoplayer2.source.MediaSource) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters)

Aggregations

Test (org.junit.Test)182 MediaSource (com.google.android.exoplayer2.source.MediaSource)117 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)117 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)74 MediaItem (com.google.android.exoplayer2.MediaItem)70 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)70 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)69 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)60 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)51 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)51 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)51 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)50 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)50 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)45 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)39 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)39 Timeline (com.google.android.exoplayer2.Timeline)35 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)34 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)28 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)25