Search in sources :

Example 31 with DataSpec

use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.

the class DataSourceInputStreamTest method buildTestInputStream.

private static DataSourceInputStream buildTestInputStream() {
    FakeDataSource fakeDataSource = new FakeDataSource();
    fakeDataSource.getDataSet().newDefaultData().appendReadData(Arrays.copyOfRange(TEST_DATA, 0, 5)).appendReadData(Arrays.copyOfRange(TEST_DATA, 5, 10)).appendReadData(Arrays.copyOfRange(TEST_DATA, 10, 15)).appendReadData(Arrays.copyOfRange(TEST_DATA, 15, TEST_DATA.length));
    return new DataSourceInputStream(fakeDataSource, new DataSpec(Uri.EMPTY));
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource)

Example 32 with DataSpec

use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.

the class CacheKeyFactoryTest method default_dataSpecWithKey_returnsKey.

@Test
public void default_dataSpecWithKey_returnsKey() {
    Uri testUri = Uri.parse("test");
    String key = "key";
    DataSpec dataSpec = new DataSpec.Builder().setUri(testUri).setKey(key).build();
    assertThat(DEFAULT.buildCacheKey(dataSpec)).isEqualTo(key);
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Uri(android.net.Uri) Test(org.junit.Test)

Example 33 with DataSpec

use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.

the class CacheKeyFactoryTest method default_dataSpecWithoutKey_returnsUri.

@Test
public void default_dataSpecWithoutKey_returnsUri() {
    Uri testUri = Uri.parse("test");
    DataSpec dataSpec = new DataSpec.Builder().setUri(testUri).build();
    assertThat(DEFAULT.buildCacheKey(dataSpec)).isEqualTo(testUri.toString());
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Uri(android.net.Uri) Test(org.junit.Test)

Example 34 with DataSpec

use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.

the class CacheDataSourceTest method setUp.

@Before
public void setUp() throws Exception {
    testDataUri = Uri.parse("https://www.test.com/data");
    httpRequestHeaders = new HashMap<>();
    httpRequestHeaders.put("Test-key", "Test-val");
    unboundedDataSpec = buildDataSpec(/* unbounded= */
    true, /* key= */
    null);
    boundedDataSpec = buildDataSpec(/* unbounded= */
    false, /* key= */
    null);
    unboundedDataSpecWithKey = buildDataSpec(/* unbounded= */
    true, DATASPEC_KEY);
    boundedDataSpecWithKey = buildDataSpec(/* unbounded= */
    false, DATASPEC_KEY);
    defaultCacheKey = CacheKeyFactory.DEFAULT.buildCacheKey(unboundedDataSpec);
    customCacheKey = "customKey." + defaultCacheKey;
    cacheKeyFactory = dataSpec -> customCacheKey;
    tempFolder = Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
    cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    upstreamDataSource = new FakeDataSource();
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) Before(org.junit.Before)

Example 35 with DataSpec

use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.

the class CacheDataSourceTest method propagatesHttpHeadersUpstream.

@Test
public void propagatesHttpHeadersUpstream() throws Exception {
    CacheDataSource cacheDataSource = createCacheDataSource(/* setReadException= */
    false, /* unknownLength= */
    false);
    DataSpec dataSpec = buildDataSpec(/* position= */
    2, /* length= */
    5);
    cacheDataSource.open(dataSpec);
    DataSpec[] upstreamDataSpecs = upstreamDataSource.getAndClearOpenedDataSpecs();
    assertThat(upstreamDataSpecs).hasLength(1);
    assertThat(upstreamDataSpecs[0].httpRequestHeaders).isEqualTo(this.httpRequestHeaders);
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Test(org.junit.Test)

Aggregations

DataSpec (com.google.android.exoplayer2.upstream.DataSpec)118 Test (org.junit.Test)79 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)28 DataSource (com.google.android.exoplayer2.upstream.DataSource)22 Uri (android.net.Uri)17 Nullable (androidx.annotation.Nullable)17 IOException (java.io.IOException)17 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)9 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)9 HlsMediaPlaylist (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist)8 ArrayList (java.util.ArrayList)7 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)6 InterruptedIOException (java.io.InterruptedIOException)5 List (java.util.List)5 ContainerMediaChunk (com.google.android.exoplayer2.source.chunk.ContainerMediaChunk)4 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)4 DataSourceException (com.google.android.exoplayer2.upstream.DataSourceException)4 DataSourceInputStream (com.google.android.exoplayer2.upstream.DataSourceInputStream)4 HttpDataSource (com.google.android.exoplayer2.upstream.HttpDataSource)4 ByteBuffer (java.nio.ByteBuffer)4