Class DefaultDataSource

  • All Implemented Interfaces:
    DataReader, DataSource

    public final class DefaultDataSource
    extends Object
    implements DataSource
    A DataSource that supports multiple URI schemes. The supported schemes are:
    • file: For fetching data from a local file (e.g. file:///path/to/media/media.mp4, or just /path/to/media/media.mp4 because the implementation assumes that a URI without a scheme is a local file URI).
    • asset: For fetching data from an asset in the application's apk (e.g. asset:///media.mp4).
    • rawresource: For fetching data from a raw resource in the application's apk (e.g. rawresource:///resourceId, where rawResourceId is the integer identifier of the raw resource).
    • android.resource: For fetching data in the application's apk (e.g. android.resource:///resourceId or android.resource://resourceType/resourceName). See RawResourceDataSource for more information about the URI form.
    • content: For fetching data from a content URI (e.g. content://authority/path/123).
    • rtmp: For fetching data over RTMP. Only supported if the project using ExoPlayer has an explicit dependency on ExoPlayer's RTMP extension.
    • data: For parsing data inlined in the URI as defined in RFC 2397.
    • udp: For fetching data over UDP (e.g. udp://something.com/media).
    • http(s): For fetching data over HTTP and HTTPS (e.g. https://www.something.com/media.mp4), if constructed using DefaultDataSource(Context, String, boolean), or any other schemes supported by a base data source if constructed using DefaultDataSource(Context, DataSource).
    • Constructor Detail

      • DefaultDataSource

        public DefaultDataSource​(Context context,
                                 boolean allowCrossProtocolRedirects)
        Constructs a new instance, optionally configured to follow cross-protocol redirects.
        Parameters:
        context - A context.
      • DefaultDataSource

        public DefaultDataSource​(Context context,
                                 @Nullable
                                 String userAgent,
                                 boolean allowCrossProtocolRedirects)
        Constructs a new instance, optionally configured to follow cross-protocol redirects.
        Parameters:
        context - A context.
        userAgent - The user agent that will be used when requesting remote data, or null to use the default user agent of the underlying platform.
        allowCrossProtocolRedirects - Whether cross-protocol redirects (i.e. redirects from HTTP to HTTPS and vice versa) are enabled when fetching remote data.
      • DefaultDataSource

        public DefaultDataSource​(Context context,
                                 @Nullable
                                 String userAgent,
                                 int connectTimeoutMillis,
                                 int readTimeoutMillis,
                                 boolean allowCrossProtocolRedirects)
        Constructs a new instance, optionally configured to follow cross-protocol redirects.
        Parameters:
        context - A context.
        userAgent - The user agent that will be used when requesting remote data, or null to use the default user agent of the underlying platform.
        connectTimeoutMillis - The connection timeout that should be used when requesting remote data, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
        readTimeoutMillis - The read timeout that should be used when requesting remote data, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
        allowCrossProtocolRedirects - Whether cross-protocol redirects (i.e. redirects from HTTP to HTTPS and vice versa) are enabled when fetching remote data.
      • DefaultDataSource

        public DefaultDataSource​(Context context,
                                 DataSource baseDataSource)
        Constructs a new instance that delegates to a provided DataSource for URI schemes other than file, asset and content.
        Parameters:
        context - A context.
        baseDataSource - A DataSource to use for URI schemes other than file, asset and content. This DataSource should normally support at least http(s).