Class OkHttpDataSource

  • All Implemented Interfaces:
    com.vng.android.exoplayer2.upstream.DataSource, com.vng.android.exoplayer2.upstream.HttpDataSource

    public class OkHttpDataSource
    extends com.vng.android.exoplayer2.upstream.BaseDataSource
    implements com.vng.android.exoplayer2.upstream.HttpDataSource
    An HttpDataSource that delegates to Square's Call.Factory.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface com.vng.android.exoplayer2.upstream.DataSource

        com.vng.android.exoplayer2.upstream.DataSource.Factory
      • Nested classes/interfaces inherited from interface com.vng.android.exoplayer2.upstream.HttpDataSource

        com.vng.android.exoplayer2.upstream.HttpDataSource.BaseFactory, com.vng.android.exoplayer2.upstream.HttpDataSource.Factory, com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException, com.vng.android.exoplayer2.upstream.HttpDataSource.InvalidContentTypeException, com.vng.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException, com.vng.android.exoplayer2.upstream.HttpDataSource.RequestProperties
    • Field Summary

      • Fields inherited from interface com.vng.android.exoplayer2.upstream.HttpDataSource

        REJECT_PAYWALL_TYPES
    • Constructor Summary

      Constructors 
      Constructor Description
      OkHttpDataSource​(okhttp3.Call.Factory callFactory, String userAgent, com.vng.android.exoplayer2.util.Predicate<String> contentTypePredicate)  
      OkHttpDataSource​(okhttp3.Call.Factory callFactory, String userAgent, com.vng.android.exoplayer2.util.Predicate<String> contentTypePredicate, okhttp3.CacheControl cacheControl, com.vng.android.exoplayer2.upstream.HttpDataSource.RequestProperties defaultRequestProperties)  
    • Constructor Detail

      • OkHttpDataSource

        public OkHttpDataSource​(okhttp3.Call.Factory callFactory,
                                @Nullable
                                String userAgent,
                                @Nullable
                                com.vng.android.exoplayer2.util.Predicate<String> contentTypePredicate)
        Parameters:
        callFactory - A Call.Factory (typically an OkHttpClient) for use by the source.
        userAgent - An optional User-Agent string.
        contentTypePredicate - An optional Predicate. If a content type is rejected by the predicate then a HttpDataSource.InvalidContentTypeException is thrown from open(DataSpec).
      • OkHttpDataSource

        public OkHttpDataSource​(okhttp3.Call.Factory callFactory,
                                @Nullable
                                String userAgent,
                                @Nullable
                                com.vng.android.exoplayer2.util.Predicate<String> contentTypePredicate,
                                @Nullable
                                okhttp3.CacheControl cacheControl,
                                @Nullable
                                com.vng.android.exoplayer2.upstream.HttpDataSource.RequestProperties defaultRequestProperties)
        Parameters:
        callFactory - A Call.Factory (typically an OkHttpClient) for use by the source.
        userAgent - An optional User-Agent string.
        contentTypePredicate - An optional Predicate. If a content type is rejected by the predicate then a HttpDataSource.InvalidContentTypeException is thrown from open(DataSpec).
        cacheControl - An optional CacheControl for setting the Cache-Control header.
        defaultRequestProperties - The optional default HttpDataSource.RequestProperties to be sent to the server as HTTP headers on every request.
    • Method Detail

      • getUri

        @Nullable
        public Uri getUri()
        Specified by:
        getUri in interface com.vng.android.exoplayer2.upstream.DataSource
      • getResponseHeaders

        public Map<String,​List<String>> getResponseHeaders()
        Specified by:
        getResponseHeaders in interface com.vng.android.exoplayer2.upstream.DataSource
        Specified by:
        getResponseHeaders in interface com.vng.android.exoplayer2.upstream.HttpDataSource
      • setRequestProperty

        public void setRequestProperty​(String name,
                                       String value)
        Specified by:
        setRequestProperty in interface com.vng.android.exoplayer2.upstream.HttpDataSource
      • clearRequestProperty

        public void clearRequestProperty​(String name)
        Specified by:
        clearRequestProperty in interface com.vng.android.exoplayer2.upstream.HttpDataSource
      • clearAllRequestProperties

        public void clearAllRequestProperties()
        Specified by:
        clearAllRequestProperties in interface com.vng.android.exoplayer2.upstream.HttpDataSource
      • open

        public long open​(com.vng.android.exoplayer2.upstream.DataSpec dataSpec)
                  throws com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
        Specified by:
        open in interface com.vng.android.exoplayer2.upstream.DataSource
        Specified by:
        open in interface com.vng.android.exoplayer2.upstream.HttpDataSource
        Throws:
        com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
      • read

        public int read​(byte[] buffer,
                        int offset,
                        int readLength)
                 throws com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
        Specified by:
        read in interface com.vng.android.exoplayer2.upstream.DataSource
        Specified by:
        read in interface com.vng.android.exoplayer2.upstream.HttpDataSource
        Throws:
        com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
      • close

        public void close()
                   throws com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
        Specified by:
        close in interface com.vng.android.exoplayer2.upstream.DataSource
        Specified by:
        close in interface com.vng.android.exoplayer2.upstream.HttpDataSource
        Throws:
        com.vng.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException
      • bytesSkipped

        protected final long bytesSkipped()
        Returns the number of bytes that have been skipped since the most recent call to open(DataSpec).
        Returns:
        The number of bytes skipped.
      • bytesRead

        protected final long bytesRead()
        Returns the number of bytes that have been read since the most recent call to open(DataSpec).
        Returns:
        The number of bytes read.
      • bytesRemaining

        protected final long bytesRemaining()
        Returns the number of bytes that are still to be read for the current DataSpec.

        If the total length of the data being read is known, then this length minus bytesRead() is returned. If the total length is unknown, C.LENGTH_UNSET is returned.

        Returns:
        The remaining length, or C.LENGTH_UNSET.