Java 类com.google.android.exoplayer2.upstream.HttpDataSource.Factory 实例源码

项目:Exoplayer2Radio    文件:HttpMediaDrmCallback.java   
private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url,
    byte[] data, Map<String, String> requestProperties) throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }
  DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
      DataSpec.FLAG_ALLOW_GZIP);
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
  try {
    return Util.toByteArray(inputStream);
  } finally {
    Util.closeQuietly(inputStream);
  }
}
项目:K-Sonic    文件:HttpMediaDrmCallback.java   
private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url,
    byte[] data, Map<String, String> requestProperties) throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }
  DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
      DataSpec.FLAG_ALLOW_GZIP);
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
  try {
    return Util.toByteArray(inputStream);
  } finally {
    Util.closeQuietly(inputStream);
  }
}
项目:Exoplayer2Radio    文件:HttpMediaDrmCallback.java   
/**
 * @deprecated Use {@link HttpMediaDrmCallback#HttpMediaDrmCallback(String, Factory)}. Request
 *     properties can be set by calling {@link #setKeyRequestProperty(String, String)}.
 * @param defaultUrl The default license URL.
 * @param dataSourceFactory A factory from which to obtain {@link HttpDataSource} instances.
 * @param keyRequestProperties Request properties to set when making key requests, or null.
 */
@Deprecated
public HttpMediaDrmCallback(String defaultUrl, HttpDataSource.Factory dataSourceFactory,
    Map<String, String> keyRequestProperties) {
  this.dataSourceFactory = dataSourceFactory;
  this.defaultUrl = defaultUrl;
  this.keyRequestProperties = new HashMap<>();
  if (keyRequestProperties != null) {
    this.keyRequestProperties.putAll(keyRequestProperties);
  }
}
项目:K-Sonic    文件:HttpMediaDrmCallback.java   
/**
 * @deprecated Use {@link HttpMediaDrmCallback#HttpMediaDrmCallback(String, Factory)}. Request
 *     properties can be set by calling {@link #setKeyRequestProperty(String, String)}.
 * @param defaultUrl The default license URL.
 * @param dataSourceFactory A factory from which to obtain {@link HttpDataSource} instances.
 * @param keyRequestProperties Request properties to set when making key requests, or null.
 */
@Deprecated
public HttpMediaDrmCallback(String defaultUrl, HttpDataSource.Factory dataSourceFactory,
    Map<String, String> keyRequestProperties) {
  this.dataSourceFactory = dataSourceFactory;
  this.defaultUrl = defaultUrl;
  this.keyRequestProperties = new HashMap<>();
  if (keyRequestProperties != null) {
    this.keyRequestProperties.putAll(keyRequestProperties);
  }
}
项目:transistor    文件:OkHttpDataSourceFactory.java   
/**
 * @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
 *     by the sources created by the factory.
 * @param userAgent An optional User-Agent string.
 * @param listener An optional listener.
 * @param cacheControl An optional {@link CacheControl} for setting the Cache-Control header.
 */
public OkHttpDataSourceFactory(@NonNull Call.Factory callFactory, @Nullable String userAgent,
    @Nullable TransferListener<? super DataSource> listener,
    @Nullable CacheControl cacheControl) {
  this.callFactory = callFactory;
  this.userAgent = userAgent;
  this.listener = listener;
  this.cacheControl = cacheControl;
}
项目:transistor    文件:CronetDataSourceFactory.java   
/**
 * Constructs a CronetDataSourceFactory.
 * <p>
 * If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
 * fallback {@link HttpDataSource.Factory} will be used instead.
 *
 * 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 contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
 *     predicate then an {@link InvalidContentTypeException} is thrown from
 *     {@link CronetDataSource#open}.
 * @param transferListener An optional listener.
 * @param fallbackFactory A {@link HttpDataSource.Factory} which is used as a fallback in case
 *     no suitable CronetEngine can be build.
 */
public CronetDataSourceFactory(CronetEngineWrapper cronetEngineWrapper,
    Executor executor, Predicate<String> contentTypePredicate,
    TransferListener<? super DataSource> transferListener,
    HttpDataSource.Factory fallbackFactory) {
  this(cronetEngineWrapper, executor, contentTypePredicate, transferListener,
      DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, false, fallbackFactory);
}
项目:transistor    文件:CronetDataSourceFactory.java   
/**
 * Constructs a CronetDataSourceFactory.
 * <p>
 * If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
 * fallback {@link HttpDataSource.Factory} will be used instead.
 *
 * @param cronetEngineWrapper A {@link CronetEngineWrapper}.
 * @param executor The {@link java.util.concurrent.Executor} that will perform the requests.
 * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
 *     predicate then an {@link InvalidContentTypeException} is thrown from
 *     {@link CronetDataSource#open}.
 * @param transferListener An optional listener.
 * @param connectTimeoutMs The connection timeout, in milliseconds.
 * @param readTimeoutMs The read timeout, in milliseconds.
 * @param resetTimeoutOnRedirects Whether the connect timeout is reset when a redirect occurs.
 * @param fallbackFactory A {@link HttpDataSource.Factory} which is used as a fallback in case
 *     no suitable CronetEngine can be build.
 */
public CronetDataSourceFactory(CronetEngineWrapper cronetEngineWrapper,
    Executor executor, Predicate<String> contentTypePredicate,
    TransferListener<? super DataSource> transferListener, int connectTimeoutMs,
    int readTimeoutMs, boolean resetTimeoutOnRedirects,
    HttpDataSource.Factory fallbackFactory) {
  this.cronetEngineWrapper = cronetEngineWrapper;
  this.executor = executor;
  this.contentTypePredicate = contentTypePredicate;
  this.transferListener = transferListener;
  this.connectTimeoutMs = connectTimeoutMs;
  this.readTimeoutMs = readTimeoutMs;
  this.resetTimeoutOnRedirects = resetTimeoutOnRedirects;
  this.fallbackFactory = fallbackFactory;
}
项目:transistor    文件:OfflineLicenseHelper.java   
/**
 * Instantiates a new instance which uses Widevine CDM. Call {@link #release()} when the instance
 * is no longer required.
 *
 * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
 *     their own license URL.
 * @param forceDefaultLicenseUrl Whether to use {@code defaultLicenseUrl} for key requests that
 *     include their own license URL.
 * @param httpDataSourceFactory A factory from which to obtain {@link HttpDataSource} instances.
 * @return A new instance which uses Widevine CDM.
 * @throws UnsupportedDrmException If the Widevine DRM scheme is unsupported or cannot be
 *     instantiated.
 */
public static OfflineLicenseHelper<FrameworkMediaCrypto> newWidevineInstance(
    String defaultLicenseUrl, boolean forceDefaultLicenseUrl, Factory httpDataSourceFactory)
    throws UnsupportedDrmException {
  return newWidevineInstance(defaultLicenseUrl, forceDefaultLicenseUrl, httpDataSourceFactory,
      null);
}
项目:transistor    文件:OfflineLicenseHelper.java   
/**
 * Instantiates a new instance which uses Widevine CDM. Call {@link #release()} when the instance
 * is no longer required.
 *
 * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
 *     their own license URL.
 * @param forceDefaultLicenseUrl Whether to use {@code defaultLicenseUrl} for key requests that
 *     include their own license URL.
 * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
 *     to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
 * @return A new instance which uses Widevine CDM.
 * @throws UnsupportedDrmException If the Widevine DRM scheme is unsupported or cannot be
 *     instantiated.
 * @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm,
 *     MediaDrmCallback, HashMap, Handler, EventListener)
 */
public static OfflineLicenseHelper<FrameworkMediaCrypto> newWidevineInstance(
    String defaultLicenseUrl, boolean forceDefaultLicenseUrl, Factory httpDataSourceFactory,
    HashMap<String, String> optionalKeyRequestParameters)
    throws UnsupportedDrmException {
  return new OfflineLicenseHelper<>(C.WIDEVINE_UUID,
      FrameworkMediaDrm.newInstance(C.WIDEVINE_UUID),
      new HttpMediaDrmCallback(defaultLicenseUrl, forceDefaultLicenseUrl, httpDataSourceFactory),
      optionalKeyRequestParameters);
}
项目:Exoplayer2Radio    文件:HttpMediaDrmCallback.java   
/**
 * @param defaultUrl The default license URL.
 * @param dataSourceFactory A factory from which to obtain {@link HttpDataSource} instances.
 */
public HttpMediaDrmCallback(String defaultUrl, HttpDataSource.Factory dataSourceFactory) {
  this(defaultUrl, dataSourceFactory, null);
}
项目:Exoplayer2Radio    文件:OfflineLicenseHelper.java   
/**
 * Instantiates a new instance which uses Widevine CDM. Call {@link #release()} when the instance
 * is no longer required.
 *
 * @param licenseUrl The default license URL.
 * @param httpDataSourceFactory A factory from which to obtain {@link HttpDataSource} instances.
 * @return A new instance which uses Widevine CDM.
 * @throws UnsupportedDrmException If the Widevine DRM scheme is unsupported or cannot be
 *     instantiated.
 */
public static OfflineLicenseHelper<FrameworkMediaCrypto> newWidevineInstance(
    String licenseUrl, Factory httpDataSourceFactory) throws UnsupportedDrmException {
  return newWidevineInstance(
      new HttpMediaDrmCallback(licenseUrl, httpDataSourceFactory), null);
}
项目:K-Sonic    文件:HttpMediaDrmCallback.java   
/**
 * @param defaultUrl The default license URL.
 * @param dataSourceFactory A factory from which to obtain {@link HttpDataSource} instances.
 */
public HttpMediaDrmCallback(String defaultUrl, HttpDataSource.Factory dataSourceFactory) {
  this(defaultUrl, dataSourceFactory, null);
}
项目:K-Sonic    文件:OfflineLicenseHelper.java   
/**
 * Instantiates a new instance which uses Widevine CDM. Call {@link #releaseResources()} when
 * you're done with the helper instance.
 *
 * @param licenseUrl The default license URL.
 * @param httpDataSourceFactory A factory from which to obtain {@link HttpDataSource} instances.
 * @return A new instance which uses Widevine CDM.
 * @throws UnsupportedDrmException If the Widevine DRM scheme is unsupported or cannot be
 *     instantiated.
 */
public static OfflineLicenseHelper<FrameworkMediaCrypto> newWidevineInstance(
    String licenseUrl, Factory httpDataSourceFactory) throws UnsupportedDrmException {
  return newWidevineInstance(
      new HttpMediaDrmCallback(licenseUrl, httpDataSourceFactory), null);
}
项目:transistor    文件:OkHttpDataSourceFactory.java   
/**
 * @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
 *     by the sources created by the factory.
 * @param userAgent An optional User-Agent string.
 * @param listener An optional listener.
 */
public OkHttpDataSourceFactory(@NonNull Call.Factory callFactory, @Nullable String userAgent,
    @Nullable TransferListener<? super DataSource> listener) {
  this(callFactory, userAgent, listener, null);
}
项目:transistor    文件:OfflineLicenseHelper.java   
/**
 * Instantiates a new instance which uses Widevine CDM. Call {@link #release()} when the instance
 * is no longer required.
 *
 * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
 *     their own license URL.
 * @param httpDataSourceFactory A factory from which to obtain {@link HttpDataSource} instances.
 * @return A new instance which uses Widevine CDM.
 * @throws UnsupportedDrmException If the Widevine DRM scheme is unsupported or cannot be
 *     instantiated.
 */
public static OfflineLicenseHelper<FrameworkMediaCrypto> newWidevineInstance(
    String defaultLicenseUrl, Factory httpDataSourceFactory)
    throws UnsupportedDrmException {
  return newWidevineInstance(defaultLicenseUrl, false, httpDataSourceFactory, null);
}