mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Make User-Agent optional
PiperOrigin-RevId: 330593247
This commit is contained in:
parent
6290d093c1
commit
49699d398d
31 changed files with 196 additions and 100 deletions
|
|
@ -139,13 +139,12 @@ public final class MainActivity extends Activity {
|
||||||
ACTION_VIEW.equals(action)
|
ACTION_VIEW.equals(action)
|
||||||
? Assertions.checkNotNull(intent.getData())
|
? Assertions.checkNotNull(intent.getData())
|
||||||
: Uri.parse(DEFAULT_MEDIA_URI);
|
: Uri.parse(DEFAULT_MEDIA_URI);
|
||||||
String userAgent = Util.getUserAgent(this, getString(R.string.application_name));
|
|
||||||
DrmSessionManager drmSessionManager;
|
DrmSessionManager drmSessionManager;
|
||||||
if (Util.SDK_INT >= 18 && intent.hasExtra(DRM_SCHEME_EXTRA)) {
|
if (Util.SDK_INT >= 18 && intent.hasExtra(DRM_SCHEME_EXTRA)) {
|
||||||
String drmScheme = Assertions.checkNotNull(intent.getStringExtra(DRM_SCHEME_EXTRA));
|
String drmScheme = Assertions.checkNotNull(intent.getStringExtra(DRM_SCHEME_EXTRA));
|
||||||
String drmLicenseUrl = Assertions.checkNotNull(intent.getStringExtra(DRM_LICENSE_URL_EXTRA));
|
String drmLicenseUrl = Assertions.checkNotNull(intent.getStringExtra(DRM_LICENSE_URL_EXTRA));
|
||||||
UUID drmSchemeUuid = Assertions.checkNotNull(Util.getDrmUuid(drmScheme));
|
UUID drmSchemeUuid = Assertions.checkNotNull(Util.getDrmUuid(drmScheme));
|
||||||
HttpDataSource.Factory licenseDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent);
|
HttpDataSource.Factory licenseDataSourceFactory = new DefaultHttpDataSourceFactory();
|
||||||
HttpMediaDrmCallback drmCallback =
|
HttpMediaDrmCallback drmCallback =
|
||||||
new HttpMediaDrmCallback(drmLicenseUrl, licenseDataSourceFactory);
|
new HttpMediaDrmCallback(drmLicenseUrl, licenseDataSourceFactory);
|
||||||
drmSessionManager =
|
drmSessionManager =
|
||||||
|
|
@ -156,9 +155,7 @@ public final class MainActivity extends Activity {
|
||||||
drmSessionManager = DrmSessionManager.getDummyDrmSessionManager();
|
drmSessionManager = DrmSessionManager.getDummyDrmSessionManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
DataSource.Factory dataSourceFactory =
|
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this);
|
||||||
new DefaultDataSourceFactory(
|
|
||||||
this, Util.getUserAgent(this, getString(R.string.application_name)));
|
|
||||||
MediaSource mediaSource;
|
MediaSource mediaSource;
|
||||||
@C.ContentType int type = Util.inferContentType(uri, intent.getStringExtra(EXTENSION_EXTRA));
|
@C.ContentType int type = Util.inferContentType(uri, intent.getStringExtra(EXTENSION_EXTRA));
|
||||||
if (type == C.TYPE_DASH) {
|
if (type == C.TYPE_DASH) {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
|
||||||
import com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor;
|
import com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor;
|
||||||
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
|
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
|
||||||
import com.google.android.exoplayer2.util.Log;
|
import com.google.android.exoplayer2.util.Log;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
@ -50,7 +49,6 @@ public final class DemoUtil {
|
||||||
private static final String DOWNLOAD_TRACKER_ACTION_FILE = "tracked_actions";
|
private static final String DOWNLOAD_TRACKER_ACTION_FILE = "tracked_actions";
|
||||||
private static final String DOWNLOAD_CONTENT_DIRECTORY = "downloads";
|
private static final String DOWNLOAD_CONTENT_DIRECTORY = "downloads";
|
||||||
|
|
||||||
private static @MonotonicNonNull String userAgent;
|
|
||||||
private static DataSource.@MonotonicNonNull Factory dataSourceFactory;
|
private static DataSource.@MonotonicNonNull Factory dataSourceFactory;
|
||||||
private static HttpDataSource.@MonotonicNonNull Factory httpDataSourceFactory;
|
private static HttpDataSource.@MonotonicNonNull Factory httpDataSourceFactory;
|
||||||
private static @MonotonicNonNull DatabaseProvider databaseProvider;
|
private static @MonotonicNonNull DatabaseProvider databaseProvider;
|
||||||
|
|
@ -78,23 +76,12 @@ public final class DemoUtil {
|
||||||
.setExtensionRendererMode(extensionRendererMode);
|
.setExtensionRendererMode(extensionRendererMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized String getUserAgent(Context context) {
|
|
||||||
if (userAgent == null) {
|
|
||||||
userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
|
|
||||||
}
|
|
||||||
return userAgent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized HttpDataSource.Factory getHttpDataSourceFactory(Context context) {
|
public static synchronized HttpDataSource.Factory getHttpDataSourceFactory(Context context) {
|
||||||
if (httpDataSourceFactory == null) {
|
if (httpDataSourceFactory == null) {
|
||||||
context = context.getApplicationContext();
|
context = context.getApplicationContext();
|
||||||
CronetEngineWrapper cronetEngineWrapper = new CronetEngineWrapper(context);
|
CronetEngineWrapper cronetEngineWrapper = new CronetEngineWrapper(context);
|
||||||
httpDataSourceFactory =
|
httpDataSourceFactory =
|
||||||
new CronetDataSourceFactory(
|
new CronetDataSourceFactory(cronetEngineWrapper, Executors.newSingleThreadExecutor());
|
||||||
cronetEngineWrapper,
|
|
||||||
Executors.newSingleThreadExecutor(),
|
|
||||||
/* transferListener= */ null,
|
|
||||||
getUserAgent(context));
|
|
||||||
}
|
}
|
||||||
return httpDataSourceFactory;
|
return httpDataSourceFactory;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,6 @@ public class PlayerActivity extends AppCompatActivity
|
||||||
DemoUtil.buildRenderersFactory(/* context= */ this, preferExtensionDecoders);
|
DemoUtil.buildRenderersFactory(/* context= */ this, preferExtensionDecoders);
|
||||||
MediaSourceFactory mediaSourceFactory =
|
MediaSourceFactory mediaSourceFactory =
|
||||||
new DefaultMediaSourceFactory(dataSourceFactory)
|
new DefaultMediaSourceFactory(dataSourceFactory)
|
||||||
.setDrmUserAgent(DemoUtil.getUserAgent(this))
|
|
||||||
.setAdsLoaderProvider(this::getAdsLoader)
|
.setAdsLoaderProvider(this::getAdsLoader)
|
||||||
.setAdViewProvider(playerView);
|
.setAdViewProvider(playerView);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -184,13 +184,12 @@ public final class MainActivity extends Activity {
|
||||||
ACTION_VIEW.equals(action)
|
ACTION_VIEW.equals(action)
|
||||||
? Assertions.checkNotNull(intent.getData())
|
? Assertions.checkNotNull(intent.getData())
|
||||||
: Uri.parse(DEFAULT_MEDIA_URI);
|
: Uri.parse(DEFAULT_MEDIA_URI);
|
||||||
String userAgent = Util.getUserAgent(this, getString(R.string.application_name));
|
|
||||||
DrmSessionManager drmSessionManager;
|
DrmSessionManager drmSessionManager;
|
||||||
if (intent.hasExtra(DRM_SCHEME_EXTRA)) {
|
if (intent.hasExtra(DRM_SCHEME_EXTRA)) {
|
||||||
String drmScheme = Assertions.checkNotNull(intent.getStringExtra(DRM_SCHEME_EXTRA));
|
String drmScheme = Assertions.checkNotNull(intent.getStringExtra(DRM_SCHEME_EXTRA));
|
||||||
String drmLicenseUrl = Assertions.checkNotNull(intent.getStringExtra(DRM_LICENSE_URL_EXTRA));
|
String drmLicenseUrl = Assertions.checkNotNull(intent.getStringExtra(DRM_LICENSE_URL_EXTRA));
|
||||||
UUID drmSchemeUuid = Assertions.checkNotNull(Util.getDrmUuid(drmScheme));
|
UUID drmSchemeUuid = Assertions.checkNotNull(Util.getDrmUuid(drmScheme));
|
||||||
HttpDataSource.Factory licenseDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent);
|
HttpDataSource.Factory licenseDataSourceFactory = new DefaultHttpDataSourceFactory();
|
||||||
HttpMediaDrmCallback drmCallback =
|
HttpMediaDrmCallback drmCallback =
|
||||||
new HttpMediaDrmCallback(drmLicenseUrl, licenseDataSourceFactory);
|
new HttpMediaDrmCallback(drmLicenseUrl, licenseDataSourceFactory);
|
||||||
drmSessionManager =
|
drmSessionManager =
|
||||||
|
|
@ -201,9 +200,7 @@ public final class MainActivity extends Activity {
|
||||||
drmSessionManager = DrmSessionManager.getDummyDrmSessionManager();
|
drmSessionManager = DrmSessionManager.getDummyDrmSessionManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
DataSource.Factory dataSourceFactory =
|
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this);
|
||||||
new DefaultDataSourceFactory(
|
|
||||||
this, Util.getUserAgent(this, getString(R.string.application_name)));
|
|
||||||
MediaSource mediaSource;
|
MediaSource mediaSource;
|
||||||
@C.ContentType int type = Util.inferContentType(uri, intent.getStringExtra(EXTENSION_EXTRA));
|
@C.ContentType int type = Util.inferContentType(uri, intent.getStringExtra(EXTENSION_EXTRA));
|
||||||
if (type == C.TYPE_DASH) {
|
if (type == C.TYPE_DASH) {
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,8 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
private volatile long currentConnectTimeoutMs;
|
private volatile long currentConnectTimeoutMs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param cronetEngine A CronetEngine.
|
* @param cronetEngine A CronetEngine.
|
||||||
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
||||||
* be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread
|
* be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread
|
||||||
|
|
@ -168,6 +170,8 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param cronetEngine A CronetEngine.
|
* @param cronetEngine A CronetEngine.
|
||||||
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
||||||
* be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread
|
* be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread
|
||||||
|
|
@ -199,6 +203,8 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param cronetEngine A CronetEngine.
|
* @param cronetEngine A CronetEngine.
|
||||||
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
||||||
* be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread
|
* be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread
|
||||||
|
|
@ -233,6 +239,8 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param cronetEngine A CronetEngine.
|
* @param cronetEngine A CronetEngine.
|
||||||
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
||||||
* be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread
|
* be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread
|
||||||
|
|
@ -262,6 +270,8 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param cronetEngine A CronetEngine.
|
* @param cronetEngine A CronetEngine.
|
||||||
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
||||||
* be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread
|
* be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread
|
||||||
|
|
@ -301,6 +311,8 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param cronetEngine A CronetEngine.
|
* @param cronetEngine A CronetEngine.
|
||||||
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
||||||
* be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread
|
* be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.ext.cronet;
|
package com.google.android.exoplayer2.ext.cronet;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.ExoPlayerLibraryInfo.DEFAULT_USER_AGENT;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
||||||
|
|
@ -50,7 +52,7 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
||||||
private final HttpDataSource.Factory fallbackFactory;
|
private final HttpDataSource.Factory fallbackFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a CronetDataSourceFactory.
|
* Creates an instance.
|
||||||
*
|
*
|
||||||
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
|
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
|
||||||
* fallback {@link HttpDataSource.Factory} will be used instead.
|
* fallback {@link HttpDataSource.Factory} will be used instead.
|
||||||
|
|
@ -79,7 +81,24 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a CronetDataSourceFactory.
|
* Creates an instance.
|
||||||
|
*
|
||||||
|
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
|
||||||
|
* DefaultHttpDataSourceFactory} will be used instead.
|
||||||
|
*
|
||||||
|
* <p>Sets {@link CronetDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout,
|
||||||
|
* {@link CronetDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
|
||||||
|
* cross-protocol redirects.
|
||||||
|
*
|
||||||
|
* @param cronetEngineWrapper A {@link CronetEngineWrapper}.
|
||||||
|
* @param executor The {@link java.util.concurrent.Executor} that will perform the requests.
|
||||||
|
*/
|
||||||
|
public CronetDataSourceFactory(CronetEngineWrapper cronetEngineWrapper, Executor executor) {
|
||||||
|
this(cronetEngineWrapper, executor, DEFAULT_USER_AGENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance.
|
||||||
*
|
*
|
||||||
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
|
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
|
||||||
* DefaultHttpDataSourceFactory} will be used instead.
|
* DefaultHttpDataSourceFactory} will be used instead.
|
||||||
|
|
@ -93,9 +112,7 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
||||||
* @param userAgent A user agent used to create a fallback HttpDataSource if needed.
|
* @param userAgent A user agent used to create a fallback HttpDataSource if needed.
|
||||||
*/
|
*/
|
||||||
public CronetDataSourceFactory(
|
public CronetDataSourceFactory(
|
||||||
CronetEngineWrapper cronetEngineWrapper,
|
CronetEngineWrapper cronetEngineWrapper, Executor executor, String userAgent) {
|
||||||
Executor executor,
|
|
||||||
String userAgent) {
|
|
||||||
this(
|
this(
|
||||||
cronetEngineWrapper,
|
cronetEngineWrapper,
|
||||||
executor,
|
executor,
|
||||||
|
|
@ -112,7 +129,7 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a CronetDataSourceFactory.
|
* Creates an instance.
|
||||||
*
|
*
|
||||||
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
|
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
|
||||||
* DefaultHttpDataSourceFactory} will be used instead.
|
* DefaultHttpDataSourceFactory} will be used instead.
|
||||||
|
|
@ -147,7 +164,7 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a CronetDataSourceFactory.
|
* Creates an instance.
|
||||||
*
|
*
|
||||||
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
|
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
|
||||||
* fallback {@link HttpDataSource.Factory} will be used instead.
|
* fallback {@link HttpDataSource.Factory} will be used instead.
|
||||||
|
|
@ -178,7 +195,7 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a CronetDataSourceFactory.
|
* Creates an instance.
|
||||||
*
|
*
|
||||||
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
|
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
|
||||||
* fallback {@link HttpDataSource.Factory} will be used instead.
|
* fallback {@link HttpDataSource.Factory} will be used instead.
|
||||||
|
|
@ -209,7 +226,28 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a CronetDataSourceFactory.
|
* Creates an instance.
|
||||||
|
*
|
||||||
|
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
|
||||||
|
* DefaultHttpDataSourceFactory} will be used instead.
|
||||||
|
*
|
||||||
|
* <p>Sets {@link CronetDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout,
|
||||||
|
* {@link CronetDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
|
||||||
|
* cross-protocol redirects.
|
||||||
|
*
|
||||||
|
* @param cronetEngineWrapper A {@link CronetEngineWrapper}.
|
||||||
|
* @param executor The {@link java.util.concurrent.Executor} that will perform the requests.
|
||||||
|
* @param transferListener An optional listener.
|
||||||
|
*/
|
||||||
|
public CronetDataSourceFactory(
|
||||||
|
CronetEngineWrapper cronetEngineWrapper,
|
||||||
|
Executor executor,
|
||||||
|
@Nullable TransferListener transferListener) {
|
||||||
|
this(cronetEngineWrapper, executor, transferListener, DEFAULT_USER_AGENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance.
|
||||||
*
|
*
|
||||||
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
|
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
|
||||||
* DefaultHttpDataSourceFactory} will be used instead.
|
* DefaultHttpDataSourceFactory} will be used instead.
|
||||||
|
|
@ -244,7 +282,7 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a CronetDataSourceFactory.
|
* Creates an instance.
|
||||||
*
|
*
|
||||||
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
|
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
|
||||||
* DefaultHttpDataSourceFactory} will be used instead.
|
* DefaultHttpDataSourceFactory} will be used instead.
|
||||||
|
|
@ -277,7 +315,7 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a CronetDataSourceFactory.
|
* Creates an instance.
|
||||||
*
|
*
|
||||||
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
|
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
|
||||||
* fallback {@link HttpDataSource.Factory} will be used instead.
|
* fallback {@link HttpDataSource.Factory} will be used instead.
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,7 @@ public final class FlacExtractorSeekTest {
|
||||||
private FlacExtractor extractor = new FlacExtractor();
|
private FlacExtractor extractor = new FlacExtractor();
|
||||||
private FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
|
private FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
|
||||||
private DefaultDataSource dataSource =
|
private DefaultDataSource dataSource =
|
||||||
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext(), "UserAgent")
|
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext()).createDataSource();
|
||||||
.createDataSource();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void flacExtractorReads_seekTable_returnSeekableSeekMap() throws IOException {
|
public void flacExtractorReads_seekTable_returnSeekableSeekMap() throws IOException {
|
||||||
|
|
|
||||||
|
|
@ -111,8 +111,7 @@ public class FlacPlaybackTest {
|
||||||
player.addListener(this);
|
player.addListener(this);
|
||||||
MediaSource mediaSource =
|
MediaSource mediaSource =
|
||||||
new ProgressiveMediaSource.Factory(
|
new ProgressiveMediaSource.Factory(
|
||||||
new DefaultDataSourceFactory(context, "ExoPlayerExtFlacTest"),
|
new DefaultDataSourceFactory(context), MatroskaExtractor.FACTORY)
|
||||||
MatroskaExtractor.FACTORY)
|
|
||||||
.createMediaSource(MediaItem.fromUri(uri));
|
.createMediaSource(MediaItem.fromUri(uri));
|
||||||
player.setMediaSource(mediaSource);
|
player.setMediaSource(mediaSource);
|
||||||
player.prepare();
|
player.prepare();
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,6 @@ import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
|
||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -235,13 +234,10 @@ public final class ImaPlaybackTest {
|
||||||
@Override
|
@Override
|
||||||
protected MediaSource buildSource(
|
protected MediaSource buildSource(
|
||||||
HostActivity host,
|
HostActivity host,
|
||||||
String userAgent,
|
|
||||||
DrmSessionManager drmSessionManager,
|
DrmSessionManager drmSessionManager,
|
||||||
FrameLayout overlayFrameLayout) {
|
FrameLayout overlayFrameLayout) {
|
||||||
Context context = host.getApplicationContext();
|
Context context = host.getApplicationContext();
|
||||||
DataSource.Factory dataSourceFactory =
|
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context);
|
||||||
new DefaultDataSourceFactory(
|
|
||||||
context, Util.getUserAgent(context, ImaPlaybackTest.class.getSimpleName()));
|
|
||||||
MediaSource contentMediaSource =
|
MediaSource contentMediaSource =
|
||||||
new DefaultMediaSourceFactory(context).createMediaSource(MediaItem.fromUri(contentUri));
|
new DefaultMediaSourceFactory(context).createMediaSource(MediaItem.fromUri(contentUri));
|
||||||
return new AdsMediaSource(
|
return new AdsMediaSource(
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DataSpec;
|
import com.google.android.exoplayer2.upstream.DataSpec;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -128,8 +127,7 @@ import org.junit.rules.ExternalResource;
|
||||||
private final DefaultDataSourceFactory defaultDataSourceFactory;
|
private final DefaultDataSourceFactory defaultDataSourceFactory;
|
||||||
|
|
||||||
public InstrumentingDataSourceFactory(Context context) {
|
public InstrumentingDataSourceFactory(Context context) {
|
||||||
defaultDataSourceFactory =
|
defaultDataSourceFactory = new DefaultDataSourceFactory(context);
|
||||||
new DefaultDataSourceFactory(context, Util.getUserAgent(context, "media2-test"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,18 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
private long bytesRead;
|
private long bytesRead;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
|
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
||||||
|
* by the source.
|
||||||
|
*/
|
||||||
|
public OkHttpDataSource(Call.Factory callFactory) {
|
||||||
|
this(callFactory, ExoPlayerLibraryInfo.DEFAULT_USER_AGENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
||||||
* by the source.
|
* by the source.
|
||||||
* @param userAgent An optional User-Agent string.
|
* @param userAgent An optional User-Agent string.
|
||||||
|
|
@ -90,6 +102,8 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
||||||
* by the source.
|
* by the source.
|
||||||
* @param userAgent An optional User-Agent string.
|
* @param userAgent An optional User-Agent string.
|
||||||
|
|
@ -111,6 +125,8 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
||||||
* by the source.
|
* by the source.
|
||||||
* @param userAgent An optional User-Agent string.
|
* @param userAgent An optional User-Agent string.
|
||||||
|
|
@ -135,6 +151,8 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
||||||
* by the source.
|
* by the source.
|
||||||
* @param userAgent An optional User-Agent string.
|
* @param userAgent An optional User-Agent string.
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.ext.okhttp;
|
package com.google.android.exoplayer2.ext.okhttp;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.ExoPlayerLibraryInfo.DEFAULT_USER_AGENT;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource.BaseFactory;
|
import com.google.android.exoplayer2.upstream.HttpDataSource.BaseFactory;
|
||||||
|
|
@ -34,6 +36,18 @@ public final class OkHttpDataSourceFactory extends BaseFactory {
|
||||||
@Nullable private final CacheControl cacheControl;
|
@Nullable private final CacheControl cacheControl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
|
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
||||||
|
* by the sources created by the factory.
|
||||||
|
*/
|
||||||
|
public OkHttpDataSourceFactory(Call.Factory callFactory) {
|
||||||
|
this(callFactory, DEFAULT_USER_AGENT, /* listener= */ null, /* cacheControl= */ null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
||||||
* by the sources created by the factory.
|
* by the sources created by the factory.
|
||||||
* @param userAgent An optional User-Agent string.
|
* @param userAgent An optional User-Agent string.
|
||||||
|
|
@ -43,6 +57,8 @@ public final class OkHttpDataSourceFactory extends BaseFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
||||||
* by the sources created by the factory.
|
* by the sources created by the factory.
|
||||||
* @param userAgent An optional User-Agent string.
|
* @param userAgent An optional User-Agent string.
|
||||||
|
|
@ -54,6 +70,8 @@ public final class OkHttpDataSourceFactory extends BaseFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
||||||
* by the sources created by the factory.
|
* by the sources created by the factory.
|
||||||
* @param userAgent An optional User-Agent string.
|
* @param userAgent An optional User-Agent string.
|
||||||
|
|
@ -65,6 +83,8 @@ public final class OkHttpDataSourceFactory extends BaseFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
||||||
* by the sources created by the factory.
|
* by the sources created by the factory.
|
||||||
* @param userAgent An optional User-Agent string.
|
* @param userAgent An optional User-Agent string.
|
||||||
|
|
|
||||||
|
|
@ -92,8 +92,7 @@ public class OpusPlaybackTest {
|
||||||
player.addListener(this);
|
player.addListener(this);
|
||||||
MediaSource mediaSource =
|
MediaSource mediaSource =
|
||||||
new ProgressiveMediaSource.Factory(
|
new ProgressiveMediaSource.Factory(
|
||||||
new DefaultDataSourceFactory(context, "ExoPlayerExtOpusTest"),
|
new DefaultDataSourceFactory(context), MatroskaExtractor.FACTORY)
|
||||||
MatroskaExtractor.FACTORY)
|
|
||||||
.createMediaSource(MediaItem.fromUri(uri));
|
.createMediaSource(MediaItem.fromUri(uri));
|
||||||
player.setMediaSource(mediaSource);
|
player.setMediaSource(mediaSource);
|
||||||
player.prepare();
|
player.prepare();
|
||||||
|
|
|
||||||
|
|
@ -121,8 +121,7 @@ public class VpxPlaybackTest {
|
||||||
player.addListener(this);
|
player.addListener(this);
|
||||||
MediaSource mediaSource =
|
MediaSource mediaSource =
|
||||||
new ProgressiveMediaSource.Factory(
|
new ProgressiveMediaSource.Factory(
|
||||||
new DefaultDataSourceFactory(context, "ExoPlayerExtVp9Test"),
|
new DefaultDataSourceFactory(context), MatroskaExtractor.FACTORY)
|
||||||
MatroskaExtractor.FACTORY)
|
|
||||||
.createMediaSource(MediaItem.fromUri(uri));
|
.createMediaSource(MediaItem.fromUri(uri));
|
||||||
player
|
player
|
||||||
.createMessage(videoRenderer)
|
.createMessage(videoRenderer)
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2;
|
package com.google.android.exoplayer2;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -45,6 +46,10 @@ public final class ExoPlayerLibraryInfo {
|
||||||
// Intentionally hardcoded. Do not derive from other constants (e.g. VERSION) or vice versa.
|
// Intentionally hardcoded. Do not derive from other constants (e.g. VERSION) or vice versa.
|
||||||
public static final int VERSION_INT = 2012000;
|
public static final int VERSION_INT = 2012000;
|
||||||
|
|
||||||
|
/** The default user agent for requests made by the library. */
|
||||||
|
public static final String DEFAULT_USER_AGENT =
|
||||||
|
VERSION_SLASHY + " (Linux;Android " + Build.VERSION.RELEASE + ") " + VERSION_SLASHY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the library was compiled with {@link com.google.android.exoplayer2.util.Assertions}
|
* Whether the library was compiled with {@link com.google.android.exoplayer2.util.Assertions}
|
||||||
* checks enabled.
|
* checks enabled.
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import android.net.Uri;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
|
||||||
import com.google.android.exoplayer2.MediaItem;
|
import com.google.android.exoplayer2.MediaItem;
|
||||||
import com.google.android.exoplayer2.drm.DrmSessionManager;
|
import com.google.android.exoplayer2.drm.DrmSessionManager;
|
||||||
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
|
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
|
||||||
|
|
@ -115,9 +114,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||||
* @param context Any context.
|
* @param context Any context.
|
||||||
*/
|
*/
|
||||||
public DefaultMediaSourceFactory(Context context) {
|
public DefaultMediaSourceFactory(Context context) {
|
||||||
this(
|
this(new DefaultDataSourceFactory(context));
|
||||||
new DefaultDataSourceFactory(
|
|
||||||
context, Util.getUserAgent(context, ExoPlayerLibraryInfo.VERSION_SLASHY)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,11 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source;
|
package com.google.android.exoplayer2.source;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.ExoPlayerLibraryInfo.DEFAULT_USER_AGENT;
|
||||||
import static com.google.android.exoplayer2.drm.DefaultDrmSessionManager.MODE_PLAYBACK;
|
import static com.google.android.exoplayer2.drm.DefaultDrmSessionManager.MODE_PLAYBACK;
|
||||||
import static com.google.android.exoplayer2.util.Util.castNonNull;
|
import static com.google.android.exoplayer2.util.Util.castNonNull;
|
||||||
|
|
||||||
import android.os.Build;
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
|
||||||
import com.google.android.exoplayer2.MediaItem;
|
import com.google.android.exoplayer2.MediaItem;
|
||||||
import com.google.android.exoplayer2.drm.DefaultDrmSessionManager;
|
import com.google.android.exoplayer2.drm.DefaultDrmSessionManager;
|
||||||
import com.google.android.exoplayer2.drm.DrmSessionManager;
|
import com.google.android.exoplayer2.drm.DrmSessionManager;
|
||||||
|
|
@ -36,13 +35,6 @@ import java.util.Map;
|
||||||
/** A helper to create a {@link DrmSessionManager} from a {@link MediaItem}. */
|
/** A helper to create a {@link DrmSessionManager} from a {@link MediaItem}. */
|
||||||
public final class MediaSourceDrmHelper {
|
public final class MediaSourceDrmHelper {
|
||||||
|
|
||||||
private static final String DEFAULT_USER_AGENT =
|
|
||||||
ExoPlayerLibraryInfo.VERSION_SLASHY
|
|
||||||
+ " (Linux;Android "
|
|
||||||
+ Build.VERSION.RELEASE
|
|
||||||
+ ") "
|
|
||||||
+ ExoPlayerLibraryInfo.VERSION_SLASHY;
|
|
||||||
|
|
||||||
@Nullable private HttpDataSource.Factory drmHttpDataSourceFactory;
|
@Nullable private HttpDataSource.Factory drmHttpDataSourceFactory;
|
||||||
@Nullable private String userAgent;
|
@Nullable private String userAgent;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.upstream;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Log;
|
import com.google.android.exoplayer2.util.Log;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
|
|
@ -74,6 +75,20 @@ public final class DefaultDataSource implements DataSource {
|
||||||
|
|
||||||
@Nullable private DataSource dataSource;
|
@Nullable private DataSource dataSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new instance, optionally configured to follow cross-protocol redirects.
|
||||||
|
*
|
||||||
|
* @param context A context.
|
||||||
|
*/
|
||||||
|
public DefaultDataSource(Context context, boolean allowCrossProtocolRedirects) {
|
||||||
|
this(
|
||||||
|
context,
|
||||||
|
ExoPlayerLibraryInfo.DEFAULT_USER_AGENT,
|
||||||
|
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
|
||||||
|
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
|
||||||
|
allowCrossProtocolRedirects);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new instance, optionally configured to follow cross-protocol redirects.
|
* Constructs a new instance, optionally configured to follow cross-protocol redirects.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.upstream;
|
package com.google.android.exoplayer2.upstream;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.ExoPlayerLibraryInfo.DEFAULT_USER_AGENT;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.upstream.DataSource.Factory;
|
import com.google.android.exoplayer2.upstream.DataSource.Factory;
|
||||||
|
|
@ -29,6 +31,11 @@ public final class DefaultDataSourceFactory implements Factory {
|
||||||
@Nullable private final TransferListener listener;
|
@Nullable private final TransferListener listener;
|
||||||
private final DataSource.Factory baseDataSourceFactory;
|
private final DataSource.Factory baseDataSourceFactory;
|
||||||
|
|
||||||
|
/** @param context A context. */
|
||||||
|
public DefaultDataSourceFactory(Context context) {
|
||||||
|
this(context, DEFAULT_USER_AGENT, /* listener= */ null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param context A context.
|
* @param context A context.
|
||||||
* @param userAgent The User-Agent string that should be used.
|
* @param userAgent The User-Agent string that should be used.
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import android.text.TextUtils;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
||||||
import com.google.android.exoplayer2.upstream.DataSpec.HttpMethod;
|
import com.google.android.exoplayer2.upstream.DataSpec.HttpMethod;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Log;
|
import com.google.android.exoplayer2.util.Log;
|
||||||
|
|
@ -97,12 +98,26 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
||||||
private long bytesSkipped;
|
private long bytesSkipped;
|
||||||
private long bytesRead;
|
private long bytesRead;
|
||||||
|
|
||||||
/** @param userAgent The User-Agent string that should be used. */
|
/** Creates an instance. */
|
||||||
|
public DefaultHttpDataSource() {
|
||||||
|
this(
|
||||||
|
ExoPlayerLibraryInfo.DEFAULT_USER_AGENT,
|
||||||
|
DEFAULT_CONNECT_TIMEOUT_MILLIS,
|
||||||
|
DEFAULT_READ_TIMEOUT_MILLIS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
|
* @param userAgent The User-Agent string that should be used.
|
||||||
|
*/
|
||||||
public DefaultHttpDataSource(String userAgent) {
|
public DefaultHttpDataSource(String userAgent) {
|
||||||
this(userAgent, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS);
|
this(userAgent, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param userAgent The User-Agent string that should be used.
|
* @param userAgent The User-Agent string that should be used.
|
||||||
* @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is
|
* @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is
|
||||||
* interpreted as an infinite timeout.
|
* interpreted as an infinite timeout.
|
||||||
|
|
@ -119,6 +134,8 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param userAgent The User-Agent string that should be used.
|
* @param userAgent The User-Agent string that should be used.
|
||||||
* @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is
|
* @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is
|
||||||
* interpreted as an infinite timeout. Pass {@link #DEFAULT_CONNECT_TIMEOUT_MILLIS} to use the
|
* interpreted as an infinite timeout. Pass {@link #DEFAULT_CONNECT_TIMEOUT_MILLIS} to use the
|
||||||
|
|
@ -146,6 +163,8 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param userAgent The User-Agent string that should be used.
|
* @param userAgent The User-Agent string that should be used.
|
||||||
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
||||||
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from {@link
|
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from {@link
|
||||||
|
|
@ -164,6 +183,8 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param userAgent The User-Agent string that should be used.
|
* @param userAgent The User-Agent string that should be used.
|
||||||
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
||||||
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from {@link
|
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from {@link
|
||||||
|
|
@ -192,6 +213,8 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
* @param userAgent The User-Agent string that should be used.
|
* @param userAgent The User-Agent string that should be used.
|
||||||
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
||||||
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from {@link
|
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from {@link
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.upstream;
|
package com.google.android.exoplayer2.upstream;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.ExoPlayerLibraryInfo.DEFAULT_USER_AGENT;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource.BaseFactory;
|
import com.google.android.exoplayer2.upstream.HttpDataSource.BaseFactory;
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
|
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
|
||||||
|
|
@ -30,10 +32,18 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory {
|
||||||
private final boolean allowCrossProtocolRedirects;
|
private final boolean allowCrossProtocolRedirects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a DefaultHttpDataSourceFactory. Sets {@link
|
* Creates an instance. Sets {@link DefaultHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the
|
||||||
* DefaultHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link
|
* connection timeout, {@link DefaultHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read
|
||||||
* DefaultHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
|
* timeout and disables cross-protocol redirects.
|
||||||
* cross-protocol redirects.
|
*/
|
||||||
|
public DefaultHttpDataSourceFactory() {
|
||||||
|
this(DEFAULT_USER_AGENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance. Sets {@link DefaultHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the
|
||||||
|
* connection timeout, {@link DefaultHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read
|
||||||
|
* timeout and disables cross-protocol redirects.
|
||||||
*
|
*
|
||||||
* @param userAgent The User-Agent string that should be used.
|
* @param userAgent The User-Agent string that should be used.
|
||||||
*/
|
*/
|
||||||
|
|
@ -42,10 +52,9 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a DefaultHttpDataSourceFactory. Sets {@link
|
* Creates an instance. Sets {@link DefaultHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the
|
||||||
* DefaultHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link
|
* connection timeout, {@link DefaultHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read
|
||||||
* DefaultHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
|
* timeout and disables cross-protocol redirects.
|
||||||
* cross-protocol redirects.
|
|
||||||
*
|
*
|
||||||
* @param userAgent The User-Agent string that should be used.
|
* @param userAgent The User-Agent string that should be used.
|
||||||
* @param listener An optional listener.
|
* @param listener An optional listener.
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,6 @@ import com.google.android.exoplayer2.upstream.Loader;
|
||||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Clock;
|
import com.google.android.exoplayer2.util.Clock;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -5552,8 +5551,7 @@ public final class ExoPlayerTest {
|
||||||
AdsMediaSource adsMediaSource =
|
AdsMediaSource adsMediaSource =
|
||||||
new AdsMediaSource(
|
new AdsMediaSource(
|
||||||
new FakeMediaSource(new FakeTimeline(/* windowCount= */ 1)),
|
new FakeMediaSource(new FakeTimeline(/* windowCount= */ 1)),
|
||||||
new DefaultDataSourceFactory(
|
new DefaultDataSourceFactory(context),
|
||||||
context, Util.getUserAgent(context, ExoPlayerLibraryInfo.VERSION_SLASHY)),
|
|
||||||
new FakeAdsLoader(),
|
new FakeAdsLoader(),
|
||||||
new FakeAdViewProvider());
|
new FakeAdViewProvider());
|
||||||
Exception[] exception = {null};
|
Exception[] exception = {null};
|
||||||
|
|
@ -5590,8 +5588,7 @@ public final class ExoPlayerTest {
|
||||||
AdsMediaSource adsMediaSource =
|
AdsMediaSource adsMediaSource =
|
||||||
new AdsMediaSource(
|
new AdsMediaSource(
|
||||||
mediaSource,
|
mediaSource,
|
||||||
new DefaultDataSourceFactory(
|
new DefaultDataSourceFactory(context),
|
||||||
context, Util.getUserAgent(context, ExoPlayerLibraryInfo.VERSION_SLASHY)),
|
|
||||||
new FakeAdsLoader(),
|
new FakeAdsLoader(),
|
||||||
new FakeAdViewProvider());
|
new FakeAdViewProvider());
|
||||||
final Exception[] exception = {null};
|
final Exception[] exception = {null};
|
||||||
|
|
@ -5630,8 +5627,7 @@ public final class ExoPlayerTest {
|
||||||
AdsMediaSource adsMediaSource =
|
AdsMediaSource adsMediaSource =
|
||||||
new AdsMediaSource(
|
new AdsMediaSource(
|
||||||
mediaSource,
|
mediaSource,
|
||||||
new DefaultDataSourceFactory(
|
new DefaultDataSourceFactory(context),
|
||||||
context, Util.getUserAgent(context, ExoPlayerLibraryInfo.VERSION_SLASHY)),
|
|
||||||
new FakeAdsLoader(),
|
new FakeAdsLoader(),
|
||||||
new FakeAdViewProvider());
|
new FakeAdViewProvider());
|
||||||
final Exception[] exception = {null};
|
final Exception[] exception = {null};
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ public final class AmrExtractorSeekTest {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
dataSource =
|
dataSource =
|
||||||
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext(), "UserAgent")
|
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext())
|
||||||
.createDataSource();
|
.createDataSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,7 @@ public class FlacExtractorSeekTest {
|
||||||
private FlacExtractor extractor = new FlacExtractor();
|
private FlacExtractor extractor = new FlacExtractor();
|
||||||
private FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
|
private FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
|
||||||
private DefaultDataSource dataSource =
|
private DefaultDataSource dataSource =
|
||||||
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext(), "UserAgent")
|
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext()).createDataSource();
|
||||||
.createDataSource();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void flacExtractorReads_seekTable_returnSeekableSeekMap() throws IOException {
|
public void flacExtractorReads_seekTable_returnSeekableSeekMap() throws IOException {
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ public class ConstantBitrateSeekerTest {
|
||||||
extractor = new Mp3Extractor();
|
extractor = new Mp3Extractor();
|
||||||
extractorOutput = new FakeExtractorOutput();
|
extractorOutput = new FakeExtractorOutput();
|
||||||
dataSource =
|
dataSource =
|
||||||
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext(), "UserAgent")
|
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext())
|
||||||
.createDataSource();
|
.createDataSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ public class IndexSeekerTest {
|
||||||
extractor = new Mp3Extractor(FLAG_ENABLE_INDEX_SEEKING);
|
extractor = new Mp3Extractor(FLAG_ENABLE_INDEX_SEEKING);
|
||||||
extractorOutput = new FakeExtractorOutput();
|
extractorOutput = new FakeExtractorOutput();
|
||||||
dataSource =
|
dataSource =
|
||||||
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext(), "UserAgent")
|
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext())
|
||||||
.createDataSource();
|
.createDataSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ public final class AdtsExtractorSeekTest {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
dataSource =
|
dataSource =
|
||||||
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext(), "UserAgent")
|
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext())
|
||||||
.createDataSource();
|
.createDataSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ public final class PsExtractorSeekTest {
|
||||||
expectedTrackOutput = expectedOutput.trackOutputs.get(VIDEO_TRACK_ID);
|
expectedTrackOutput = expectedOutput.trackOutputs.get(VIDEO_TRACK_ID);
|
||||||
|
|
||||||
dataSource =
|
dataSource =
|
||||||
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext(), "UserAgent")
|
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext())
|
||||||
.createDataSource();
|
.createDataSource();
|
||||||
totalInputLength = readInputLength();
|
totalInputLength = readInputLength();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ public final class TsExtractorSeekTest {
|
||||||
.get(AUDIO_TRACK_ID);
|
.get(AUDIO_TRACK_ID);
|
||||||
|
|
||||||
dataSource =
|
dataSource =
|
||||||
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext(), "UserAgent")
|
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext())
|
||||||
.createDataSource();
|
.createDataSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -258,12 +258,12 @@ import java.util.List;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DrmSessionManager buildDrmSessionManager(final String userAgent) {
|
protected DrmSessionManager buildDrmSessionManager() {
|
||||||
if (widevineLicenseUrl == null) {
|
if (widevineLicenseUrl == null) {
|
||||||
return DrmSessionManager.getDummyDrmSessionManager();
|
return DrmSessionManager.getDummyDrmSessionManager();
|
||||||
}
|
}
|
||||||
MediaDrmCallback drmCallback =
|
MediaDrmCallback drmCallback =
|
||||||
new HttpMediaDrmCallback(widevineLicenseUrl, new DefaultHttpDataSourceFactory(userAgent));
|
new HttpMediaDrmCallback(widevineLicenseUrl, new DefaultHttpDataSourceFactory());
|
||||||
DefaultDrmSessionManager drmSessionManager =
|
DefaultDrmSessionManager drmSessionManager =
|
||||||
new DefaultDrmSessionManager.Builder()
|
new DefaultDrmSessionManager.Builder()
|
||||||
.setUuidAndExoMediaDrmProvider(
|
.setUuidAndExoMediaDrmProvider(
|
||||||
|
|
@ -301,13 +301,12 @@ import java.util.List;
|
||||||
@Override
|
@Override
|
||||||
protected MediaSource buildSource(
|
protected MediaSource buildSource(
|
||||||
HostActivity host,
|
HostActivity host,
|
||||||
String userAgent,
|
|
||||||
DrmSessionManager drmSessionManager,
|
DrmSessionManager drmSessionManager,
|
||||||
FrameLayout overlayFrameLayout) {
|
FrameLayout overlayFrameLayout) {
|
||||||
DataSource.Factory dataSourceFactory =
|
DataSource.Factory dataSourceFactory =
|
||||||
this.dataSourceFactory != null
|
this.dataSourceFactory != null
|
||||||
? this.dataSourceFactory
|
? this.dataSourceFactory
|
||||||
: new DefaultDataSourceFactory(host, userAgent);
|
: new DefaultDataSourceFactory(host);
|
||||||
return new DashMediaSource.Factory(dataSourceFactory)
|
return new DashMediaSource.Factory(dataSourceFactory)
|
||||||
.setDrmSessionManager(drmSessionManager)
|
.setDrmSessionManager(drmSessionManager)
|
||||||
.setLoadErrorHandlingPolicy(new DefaultLoadErrorHandlingPolicy(MIN_LOADABLE_RETRY_COUNT))
|
.setLoadErrorHandlingPolicy(new DefaultLoadErrorHandlingPolicy(MIN_LOADABLE_RETRY_COUNT))
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,6 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
|
||||||
this.surface = surface;
|
this.surface = surface;
|
||||||
// Build the player.
|
// Build the player.
|
||||||
trackSelector = buildTrackSelector(host);
|
trackSelector = buildTrackSelector(host);
|
||||||
String userAgent = "ExoPlayerPlaybackTests";
|
|
||||||
player = buildExoPlayer(host, surface, trackSelector);
|
player = buildExoPlayer(host, surface, trackSelector);
|
||||||
player.play();
|
player.play();
|
||||||
player.addAnalyticsListener(this);
|
player.addAnalyticsListener(this);
|
||||||
|
|
@ -140,10 +139,8 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
|
||||||
pendingSchedule.start(player, trackSelector, surface, actionHandler, /* callback= */ null);
|
pendingSchedule.start(player, trackSelector, surface, actionHandler, /* callback= */ null);
|
||||||
pendingSchedule = null;
|
pendingSchedule = null;
|
||||||
}
|
}
|
||||||
DrmSessionManager drmSessionManager = buildDrmSessionManager(userAgent);
|
DrmSessionManager drmSessionManager = buildDrmSessionManager();
|
||||||
player.setMediaSource(
|
player.setMediaSource(buildSource(host, drmSessionManager, overlayFrameLayout));
|
||||||
buildSource(
|
|
||||||
host, Util.getUserAgent(host, userAgent), drmSessionManager, overlayFrameLayout));
|
|
||||||
player.prepare();
|
player.prepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -232,7 +229,7 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DrmSessionManager buildDrmSessionManager(String userAgent) {
|
protected DrmSessionManager buildDrmSessionManager() {
|
||||||
// Do nothing. Interested subclasses may override.
|
// Do nothing. Interested subclasses may override.
|
||||||
return DrmSessionManager.getDummyDrmSessionManager();
|
return DrmSessionManager.getDummyDrmSessionManager();
|
||||||
}
|
}
|
||||||
|
|
@ -256,7 +253,6 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
|
||||||
|
|
||||||
protected abstract MediaSource buildSource(
|
protected abstract MediaSource buildSource(
|
||||||
HostActivity host,
|
HostActivity host,
|
||||||
String userAgent,
|
|
||||||
DrmSessionManager drmSessionManager,
|
DrmSessionManager drmSessionManager,
|
||||||
FrameLayout overlayFrameLayout);
|
FrameLayout overlayFrameLayout);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue