Search in sources :

Example 1 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class MediaItemTest method builderSetStreamKeys_setsStreamKeys.

@Test
public void builderSetStreamKeys_setsStreamKeys() {
    List<StreamKey> streamKeys = new ArrayList<>();
    streamKeys.add(new StreamKey(1, 0, 0));
    streamKeys.add(new StreamKey(0, 1, 1));
    MediaItem mediaItem = new MediaItem.Builder().setUri(URI_STRING).setStreamKeys(streamKeys).build();
    assertThat(mediaItem.localConfiguration.streamKeys).isEqualTo(streamKeys);
}
Also used : ArrayList(java.util.ArrayList) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 2 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class SsMediaPeriod method getStreamKeys.

@Override
public List<StreamKey> getStreamKeys(List<ExoTrackSelection> trackSelections) {
    List<StreamKey> streamKeys = new ArrayList<>();
    for (int selectionIndex = 0; selectionIndex < trackSelections.size(); selectionIndex++) {
        ExoTrackSelection trackSelection = trackSelections.get(selectionIndex);
        int streamElementIndex = trackGroups.indexOf(trackSelection.getTrackGroup());
        for (int i = 0; i < trackSelection.length(); i++) {
            streamKeys.add(new StreamKey(streamElementIndex, trackSelection.getIndexInTrackGroup(i)));
        }
    }
    return streamKeys;
}
Also used : ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) ArrayList(java.util.ArrayList) StreamKey(com.google.android.exoplayer2.offline.StreamKey)

Example 3 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class DashDownloadTest method downloadContent.

private DashDownloader downloadContent() throws Exception {
    DashManifest dashManifest = DashUtil.loadManifest(httpDataSourceFactory.createDataSource(), MANIFEST_URI);
    ArrayList<StreamKey> keys = new ArrayList<>();
    for (int pIndex = 0; pIndex < dashManifest.getPeriodCount(); pIndex++) {
        List<AdaptationSet> adaptationSets = dashManifest.getPeriod(pIndex).adaptationSets;
        for (int aIndex = 0; aIndex < adaptationSets.size(); aIndex++) {
            AdaptationSet adaptationSet = adaptationSets.get(aIndex);
            List<Representation> representations = adaptationSet.representations;
            for (int rIndex = 0; rIndex < representations.size(); rIndex++) {
                String id = representations.get(rIndex).format.id;
                if (DashTestData.AAC_AUDIO_REPRESENTATION_ID.equals(id) || DashTestData.H264_CDD_FIXED.equals(id)) {
                    keys.add(new StreamKey(pIndex, aIndex, rIndex));
                }
            }
        }
    }
    CacheDataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(cache).setUpstreamDataSourceFactory(httpDataSourceFactory);
    return new DashDownloader(new MediaItem.Builder().setUri(MANIFEST_URI).setStreamKeys(keys).build(), cacheDataSourceFactory);
}
Also used : DashDownloader(com.google.android.exoplayer2.source.dash.offline.DashDownloader) DashManifest(com.google.android.exoplayer2.source.dash.manifest.DashManifest) ArrayList(java.util.ArrayList) Representation(com.google.android.exoplayer2.source.dash.manifest.Representation) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) AdaptationSet(com.google.android.exoplayer2.source.dash.manifest.AdaptationSet) StreamKey(com.google.android.exoplayer2.offline.StreamKey)

Example 4 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class SsManifestTest method copy.

@Test
public void copy() throws Exception {
    Format[][] formats = newFormats(2, 3);
    SsManifest sourceManifest = createSsManifest(createStreamElement("1", formats[0]), createStreamElement("2", formats[1]));
    List<StreamKey> keys = Arrays.asList(new StreamKey(0, 0), new StreamKey(0, 2), new StreamKey(1, 0));
    // Keys don't need to be in any particular order
    Collections.shuffle(keys, new Random(0));
    SsManifest copyManifest = sourceManifest.copy(keys);
    SsManifest expectedManifest = createSsManifest(createStreamElement("1", formats[0][0], formats[0][2]), createStreamElement("2", formats[1][0]));
    assertManifestEquals(expectedManifest, copyManifest);
}
Also used : Random(java.util.Random) SsTestUtils.createSsManifest(com.google.android.exoplayer2.source.smoothstreaming.SsTestUtils.createSsManifest) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 5 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class DownloadServiceDashTest method downloadKeys.

private void downloadKeys(StreamKey... keys) {
    ArrayList<StreamKey> keysList = new ArrayList<>();
    Collections.addAll(keysList, keys);
    DownloadRequest action = new DownloadRequest.Builder(TEST_ID, TEST_MPD_URI).setMimeType(MimeTypes.APPLICATION_MPD).setStreamKeys(keysList).build();
    testThread.runOnMainThread(() -> {
        Intent startIntent = DownloadService.buildAddDownloadIntent(context, DownloadService.class, action, /* foreground= */
        false);
        dashDownloadService.onStartCommand(startIntent, 0, 0);
    });
}
Also used : ArrayList(java.util.ArrayList) DownloadRequest(com.google.android.exoplayer2.offline.DownloadRequest) Intent(android.content.Intent) StreamKey(com.google.android.exoplayer2.offline.StreamKey)

Aggregations

StreamKey (com.google.android.exoplayer2.offline.StreamKey)27 Test (org.junit.Test)18 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)11 ArrayList (java.util.ArrayList)10 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)5 DefaultDownloaderFactory (com.google.android.exoplayer2.offline.DefaultDownloaderFactory)4 RequestSet (com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet)4 ExoTrackSelection (com.google.android.exoplayer2.trackselection.ExoTrackSelection)4 Downloader (com.google.android.exoplayer2.offline.Downloader)3 DownloaderFactory (com.google.android.exoplayer2.offline.DownloaderFactory)3 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)3 Context (android.content.Context)2 Format (com.google.android.exoplayer2.Format)2 DefaultDownloadIndex (com.google.android.exoplayer2.offline.DefaultDownloadIndex)2 DownloadRequest (com.google.android.exoplayer2.offline.DownloadRequest)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)2 AdaptationSet (com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)2 SsTestUtils.createSsManifest (com.google.android.exoplayer2.source.smoothstreaming.SsTestUtils.createSsManifest)2 DummyMainThread (com.google.android.exoplayer2.testutil.DummyMainThread)2