Search in sources :

Example 11 with Action

use of com.google.android.exoplayer2.testutil.Action in project LeafPic by HoraApps.

the class PlayerActivity method initializePlayer.

// Internal methods
private void initializePlayer() {
    Intent intent = getIntent();
    boolean needNewPlayer = player == null;
    if (needNewPlayer) {
        TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
        trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
        trackSelectionHelper = new TrackSelectionHelper(trackSelector, adaptiveTrackSelectionFactory, getThemeHelper());
        lastSeenTrackGroupArray = null;
        UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA) ? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA)) : null;
        DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
        if (drmSchemeUuid != null) {
            String drmLicenseUrl = intent.getStringExtra(DRM_LICENSE_URL);
            String[] keyRequestPropertiesArray = intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES);
            boolean multiSession = intent.getBooleanExtra(DRM_MULTI_SESSION, false);
            int errorStringId = R.string.error_drm_unknown;
            try {
                drmSessionManager = buildDrmSessionManagerV18(drmSchemeUuid, drmLicenseUrl, keyRequestPropertiesArray, multiSession);
            } catch (UnsupportedDrmException e) {
                errorStringId = e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown;
            }
            if (drmSessionManager == null) {
                showToast(errorStringId);
                return;
            }
        }
        DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER);
        player = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector);
        player.addListener(new PlayerEventListener());
        simpleExoPlayerView.setPlayer(player);
        player.setPlayWhenReady(shouldAutoPlay);
    }
    String action = intent.getAction();
    Uri[] uris;
    String[] extensions;
    if (intent.getData() != null && intent.getType() != null) {
        uris = new Uri[] { intent.getData() };
        extensions = new String[] { intent.getType() };
    } else {
        // TODO: 12/7/16 asdasd
        showToast(getString(R.string.unexpected_intent_action, action));
        return;
    }
    MediaSource[] mediaSources = new MediaSource[uris.length];
    for (int i = 0; i < uris.length; i++) {
        mediaSources[i] = buildMediaSource(uris[i], extensions[i]);
    }
    MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources);
    boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
    if (haveResumePosition) {
        player.seekTo(resumeWindow, resumePosition);
    }
    player.prepare(mediaSource, !haveResumePosition, false);
    inErrorState = false;
    supportInvalidateOptionsMenu();
}
Also used : DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) DefaultHttpDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory) ExoPlayerFactory(com.google.android.exoplayer2.ExoPlayerFactory) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) Intent(android.content.Intent) TrackSelectionHelper(org.horaapps.leafpic.views.videoplayer.TrackSelectionHelper) Uri(android.net.Uri) FrameworkMediaCrypto(com.google.android.exoplayer2.drm.FrameworkMediaCrypto) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) SsMediaSource(com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource) HlsMediaSource(com.google.android.exoplayer2.source.hls.HlsMediaSource) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) UnsupportedDrmException(com.google.android.exoplayer2.drm.UnsupportedDrmException) UUID(java.util.UUID) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection)

Example 12 with Action

use of com.google.android.exoplayer2.testutil.Action in project ExoPlayer by google.

the class DownloadManagerDashTest method saveAndLoadActionFile.

@Ignore("Disabled due to flakiness")
@Test
public void saveAndLoadActionFile() throws Throwable {
    // Configure fakeDataSet to block until interrupted when TEST_MPD is read.
    fakeDataSet.newData(TEST_MPD_URI).appendReadAction(() -> {
        try {
            // Wait until interrupted.
            while (true) {
                Thread.sleep(100000);
            }
        } catch (InterruptedException ignored) {
            Thread.currentThread().interrupt();
        }
    }).appendReadData(TEST_MPD).endData();
    // Run DM accessing code on UI/main thread as it should be. Also not to block handling of loaded
    // actions.
    runOnMainThread(() -> {
        // Setup an Action and immediately release the DM.
        DownloadRequest request = getDownloadRequest(fakeStreamKey1, fakeStreamKey2);
        downloadManager.addDownload(request);
        downloadManager.release();
    });
    assertCacheEmpty(cache);
    // Revert fakeDataSet to normal.
    fakeDataSet.setData(TEST_MPD_URI, TEST_MPD);
    testThread.runOnMainThread(this::createDownloadManager);
    // Block on the test thread.
    downloadManagerListener.blockUntilIdleAndThrowAnyFailure();
    assertCachedData(cache, fakeDataSet);
}
Also used : DownloadRequest(com.google.android.exoplayer2.offline.DownloadRequest) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with Action

use of com.google.android.exoplayer2.testutil.Action in project ExoPlayer by google.

the class CacheDataSourceTest method switchToCacheSourceWithReadOnlyCacheDataSource.

@Test
public void switchToCacheSourceWithReadOnlyCacheDataSource() throws Exception {
    // Create a fake data source with a 1 MB default data.
    FakeDataSource upstream = new FakeDataSource();
    FakeData fakeData = upstream.getDataSet().newDefaultData().appendReadData(1024 * 1024 - 1);
    // Insert an action just before the end of the data to fail the test if reading from upstream
    // reaches end of the data.
    fakeData.appendReadAction(() -> fail("Read from upstream shouldn't reach to the end of the data.")).appendReadData(1);
    // Create cache read-only CacheDataSource.
    CacheDataSource cacheDataSource = new CacheDataSource(cache, upstream, new FileDataSource(), null, 0, null);
    // Open source and read some data from upstream as the data hasn't cached yet.
    cacheDataSource.open(unboundedDataSpec);
    byte[] buffer = new byte[1024];
    cacheDataSource.read(buffer, 0, buffer.length);
    // Cache the data. Although we use another FakeDataSource instance, it shouldn't matter.
    FakeDataSource upstream2 = new FakeDataSource(new FakeDataSource().getDataSet().newDefaultData().appendReadData(1024 * 1024).endData());
    CacheWriter cacheWriter = new CacheWriter(new CacheDataSource(cache, upstream2), unboundedDataSpec, /* temporaryBuffer= */
    null, /* progressListener= */
    null);
    cacheWriter.cache();
    // Read the rest of the data.
    DataSourceUtil.readToEnd(cacheDataSource);
    cacheDataSource.close();
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource) FakeData(com.google.android.exoplayer2.testutil.FakeDataSet.FakeData) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 Intent (android.content.Intent)4 Nullable (androidx.annotation.Nullable)4 Uri (android.net.Uri)3 MediaItem (com.google.android.exoplayer2.MediaItem)3 MediaSource (com.google.android.exoplayer2.source.MediaSource)3 DashMediaSource (com.google.android.exoplayer2.source.dash.DashMediaSource)3 UUID (java.util.UUID)3 Activity (android.app.Activity)2 Bundle (android.os.Bundle)2 Surface (android.view.Surface)2 C (com.google.android.exoplayer2.C)2 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)2 Player (com.google.android.exoplayer2.Player)2 DefaultDrmSessionManager (com.google.android.exoplayer2.drm.DefaultDrmSessionManager)2 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)2 FrameworkMediaDrm (com.google.android.exoplayer2.drm.FrameworkMediaDrm)2 HttpMediaDrmCallback (com.google.android.exoplayer2.drm.HttpMediaDrmCallback)2 ProgressiveMediaSource (com.google.android.exoplayer2.source.ProgressiveMediaSource)2 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)2