Search in sources :

Example 1 with DownloadException

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

the class DashDownloaderTest method representationWithoutIndex.

@Test
public void representationWithoutIndex() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD_NO_INDEX).setRandomData("test_segment_1", 4);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet, new StreamKey(0, 0, 0));
    try {
        dashDownloader.download(progressListener);
        fail();
    } catch (DownloadException e) {
    // Expected.
    }
    dashDownloader.remove();
    assertCacheEmpty(cache);
}
Also used : DownloadException(com.google.android.exoplayer2.offline.DownloadException) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 2 with DownloadException

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

the class DashDownloader method addSegmentsForAdaptationSet.

private void addSegmentsForAdaptationSet(DataSource dataSource, AdaptationSet adaptationSet, long periodStartUs, long periodDurationUs, boolean removing, ArrayList<Segment> out) throws IOException, InterruptedException {
    for (int i = 0; i < adaptationSet.representations.size(); i++) {
        Representation representation = adaptationSet.representations.get(i);
        DashSegmentIndex index;
        try {
            index = getSegmentIndex(dataSource, adaptationSet.type, representation, removing);
            if (index == null) {
                // Loading succeeded but there was no index.
                throw new DownloadException("Missing segment index");
            }
        } catch (IOException e) {
            if (!removing) {
                throw e;
            }
            // Generating an incomplete segment list is allowed. Advance to the next representation.
            continue;
        }
        long segmentCount = index.getSegmentCount(periodDurationUs);
        if (segmentCount == DashSegmentIndex.INDEX_UNBOUNDED) {
            throw new DownloadException("Unbounded segment index");
        }
        String baseUrl = castNonNull(baseUrlExclusionList.selectBaseUrl(representation.baseUrls)).url;
        @Nullable RangedUri initializationUri = representation.getInitializationUri();
        if (initializationUri != null) {
            out.add(createSegment(representation, baseUrl, periodStartUs, initializationUri));
        }
        @Nullable RangedUri indexUri = representation.getIndexUri();
        if (indexUri != null) {
            out.add(createSegment(representation, baseUrl, periodStartUs, indexUri));
        }
        long firstSegmentNum = index.getFirstSegmentNum();
        long lastSegmentNum = firstSegmentNum + segmentCount - 1;
        for (long j = firstSegmentNum; j <= lastSegmentNum; j++) {
            out.add(createSegment(representation, baseUrl, periodStartUs + index.getTimeUs(j), index.getSegmentUrl(j)));
        }
    }
}
Also used : DownloadException(com.google.android.exoplayer2.offline.DownloadException) RangedUri(com.google.android.exoplayer2.source.dash.manifest.RangedUri) Representation(com.google.android.exoplayer2.source.dash.manifest.Representation) IOException(java.io.IOException) DashSegmentIndex(com.google.android.exoplayer2.source.dash.DashSegmentIndex) Nullable(androidx.annotation.Nullable)

Aggregations

DownloadException (com.google.android.exoplayer2.offline.DownloadException)2 Nullable (androidx.annotation.Nullable)1 StreamKey (com.google.android.exoplayer2.offline.StreamKey)1 DashSegmentIndex (com.google.android.exoplayer2.source.dash.DashSegmentIndex)1 RangedUri (com.google.android.exoplayer2.source.dash.manifest.RangedUri)1 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)1 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)1 IOException (java.io.IOException)1 Test (org.junit.Test)1