Java Code Examples for com.google.android.exoplayer2.upstream.DataSpec#isFlagSet()

The following examples show how to use com.google.android.exoplayer2.upstream.DataSpec#isFlagSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheDataSink.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public void open(DataSpec dataSpec) throws CacheDataSinkException {
  if (dataSpec.length == C.LENGTH_UNSET
      && dataSpec.isFlagSet(DataSpec.FLAG_DONT_CACHE_IF_LENGTH_UNKNOWN)) {
    this.dataSpec = null;
    return;
  }
  this.dataSpec = dataSpec;
  this.dataSpecFragmentSize =
      dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_CACHE_FRAGMENTATION) ? fragmentSize : Long.MAX_VALUE;
  dataSpecBytesWritten = 0;
  try {
    openNextOutputStream();
  } catch (IOException e) {
    throw new CacheDataSinkException(e);
  }
}
 
Example 2
Source File: CacheDataSink.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void open(DataSpec dataSpec) throws CacheDataSinkException {
  if (dataSpec.length == C.LENGTH_UNSET
      && dataSpec.isFlagSet(DataSpec.FLAG_DONT_CACHE_IF_LENGTH_UNKNOWN)) {
    this.dataSpec = null;
    return;
  }
  this.dataSpec = dataSpec;
  this.dataSpecFragmentSize =
      dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_CACHE_FRAGMENTATION) ? fragmentSize : Long.MAX_VALUE;
  dataSpecBytesWritten = 0;
  try {
    openNextOutputStream();
  } catch (IOException e) {
    throw new CacheDataSinkException(e);
  }
}
 
Example 3
Source File: CacheDataSink.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void open(DataSpec dataSpec) throws CacheDataSinkException {
  if (dataSpec.length == C.LENGTH_UNSET
      && dataSpec.isFlagSet(DataSpec.FLAG_DONT_CACHE_IF_LENGTH_UNKNOWN)) {
    this.dataSpec = null;
    return;
  }
  this.dataSpec = dataSpec;
  this.dataSpecFragmentSize =
      dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_CACHE_FRAGMENTATION) ? fragmentSize : Long.MAX_VALUE;
  dataSpecBytesWritten = 0;
  try {
    openNextOutputStream();
  } catch (IOException e) {
    throw new CacheDataSinkException(e);
  }
}
 
Example 4
Source File: CacheDataSink.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void open(DataSpec dataSpec) throws CacheDataSinkException {
  if (dataSpec.length == C.LENGTH_UNSET
      && !dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_CACHING_UNKNOWN_LENGTH)) {
    this.dataSpec = null;
    return;
  }
  this.dataSpec = dataSpec;
  dataSpecBytesWritten = 0;
  try {
    openNextOutputStream();
  } catch (IOException e) {
    throw new CacheDataSinkException(e);
  }
}
 
Example 5
Source File: CacheDataSink.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void open(DataSpec dataSpec) throws CacheDataSinkException {
  if (dataSpec.length == C.LENGTH_UNSET
      && !dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_CACHING_UNKNOWN_LENGTH)) {
    this.dataSpec = null;
    return;
  }
  this.dataSpec = dataSpec;
  dataSpecBytesWritten = 0;
  try {
    openNextOutputStream();
  } catch (IOException e) {
    throw new CacheDataSinkException(e);
  }
}
 
Example 6
Source File: CacheDataSink.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public void open(DataSpec dataSpec) throws CacheDataSinkException {
  if (dataSpec.length == C.LENGTH_UNSET
      && !dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_CACHING_UNKNOWN_LENGTH)) {
    this.dataSpec = null;
    return;
  }
  this.dataSpec = dataSpec;
  dataSpecBytesWritten = 0;
  try {
    openNextOutputStream();
  } catch (IOException e) {
    throw new CacheDataSinkException(e);
  }
}
 
Example 7
Source File: GSYDefaultHttpDataSource.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * Establishes a connection, following redirects to do so where permitted.
 */
private HttpURLConnection makeConnection(DataSpec dataSpec) throws IOException {
    URL url = new URL(dataSpec.uri.toString());
    @HttpMethod int httpMethod = dataSpec.httpMethod;
    byte[] httpBody = dataSpec.httpBody;
    long position = dataSpec.position;
    long length = dataSpec.length;
    boolean allowGzip = dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_GZIP);

    if (!allowCrossProtocolRedirects) {
        // HttpURLConnection disallows cross-protocol redirects, but otherwise performs redirection
        // automatically. This is the behavior we want, so use it.
        return makeConnection(
                url,
                httpMethod,
                httpBody,
                position,
                length,
                allowGzip,
                /* followRedirects= */ true,
                dataSpec.httpRequestHeaders);
    }

    // We need to handle redirects ourselves to allow cross-protocol redirects.
    int redirectCount = 0;
    while (redirectCount++ <= MAX_REDIRECTS) {
        HttpURLConnection connection =
                makeConnection(
                        url,
                        httpMethod,
                        httpBody,
                        position,
                        length,
                        allowGzip,
                        /* followRedirects= */ false,
                        dataSpec.httpRequestHeaders);
        int responseCode = connection.getResponseCode();
        String location = connection.getHeaderField("Location");
        if ((httpMethod == DataSpec.HTTP_METHOD_GET || httpMethod == DataSpec.HTTP_METHOD_HEAD)
                && (responseCode == HttpURLConnection.HTTP_MULT_CHOICE
                || responseCode == HttpURLConnection.HTTP_MOVED_PERM
                || responseCode == HttpURLConnection.HTTP_MOVED_TEMP
                || responseCode == HttpURLConnection.HTTP_SEE_OTHER
                || responseCode == HTTP_STATUS_TEMPORARY_REDIRECT
                || responseCode == HTTP_STATUS_PERMANENT_REDIRECT)) {
            connection.disconnect();
            url = handleRedirect(url, location);
        } else if (httpMethod == DataSpec.HTTP_METHOD_POST
                && (responseCode == HttpURLConnection.HTTP_MULT_CHOICE
                || responseCode == HttpURLConnection.HTTP_MOVED_PERM
                || responseCode == HttpURLConnection.HTTP_MOVED_TEMP
                || responseCode == HttpURLConnection.HTTP_SEE_OTHER)) {
            // POST request follows the redirect and is transformed into a GET request.
            connection.disconnect();
            httpMethod = DataSpec.HTTP_METHOD_GET;
            httpBody = null;
            url = handleRedirect(url, location);
        } else {
            return connection;
        }
    }

    // If we get here we've been redirected more times than are permitted.
    throw new NoRouteToHostException("Too many redirects: " + redirectCount);
}