Search in sources :

Example 1 with DownloadException

use of androidx.media3.exoplayer.offline.DownloadException in project media by androidx.

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(androidx.media3.exoplayer.offline.DownloadException) FakeDataSet(androidx.media3.test.utils.FakeDataSet) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 2 with DownloadException

use of androidx.media3.exoplayer.offline.DownloadException in project media by androidx.

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(androidx.media3.exoplayer.offline.DownloadException) RangedUri(androidx.media3.exoplayer.dash.manifest.RangedUri) Representation(androidx.media3.exoplayer.dash.manifest.Representation) IOException(java.io.IOException) DashSegmentIndex(androidx.media3.exoplayer.dash.DashSegmentIndex) Nullable(androidx.annotation.Nullable)

Aggregations

DownloadException (androidx.media3.exoplayer.offline.DownloadException)2 Nullable (androidx.annotation.Nullable)1 StreamKey (androidx.media3.common.StreamKey)1 DashSegmentIndex (androidx.media3.exoplayer.dash.DashSegmentIndex)1 RangedUri (androidx.media3.exoplayer.dash.manifest.RangedUri)1 Representation (androidx.media3.exoplayer.dash.manifest.Representation)1 FakeDataSet (androidx.media3.test.utils.FakeDataSet)1 IOException (java.io.IOException)1 Test (org.junit.Test)1