Java Code Examples for com.google.android.exoplayer2.upstream.HttpDataSource#Factory

The following examples show how to use com.google.android.exoplayer2.upstream.HttpDataSource#Factory . 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: DataSourceUtil.java    From react-native-video with MIT License 5 votes vote down vote up
private static HttpDataSource.Factory buildHttpDataSourceFactory(ReactContext context, DefaultBandwidthMeter bandwidthMeter, Map<String, String> requestHeaders) {
    OkHttpClient client = OkHttpClientProvider.getOkHttpClient();
    CookieJarContainer container = (CookieJarContainer) client.cookieJar();
    ForwardingCookieHandler handler = new ForwardingCookieHandler(context);
    container.setCookieJar(new JavaNetCookieJar(handler));
    OkHttpDataSourceFactory okHttpDataSourceFactory = new OkHttpDataSourceFactory(client, getUserAgent(context), bandwidthMeter);

    if (requestHeaders != null)
        okHttpDataSourceFactory.getDefaultRequestProperties().set(requestHeaders);

    return okHttpDataSourceFactory;
}
 
Example 2
Source File: HttpMediaDrmCallback.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * @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);
  }
}
 
Example 3
Source File: HttpMediaDrmCallback.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private static byte[] executePost(
    HttpDataSource.Factory dataSourceFactory,
    String url,
    @Nullable byte[] httpBody,
    @Nullable 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());
    }
  }

  int manualRedirectCount = 0;
  while (true) {
    DataSpec dataSpec =
        new DataSpec(
            Uri.parse(url),
            DataSpec.HTTP_METHOD_POST,
            httpBody,
            /* absoluteStreamPosition= */ 0,
            /* position= */ 0,
            /* length= */ C.LENGTH_UNSET,
            /* key= */ null,
            DataSpec.FLAG_ALLOW_GZIP);
    DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
      return Util.toByteArray(inputStream);
    } catch (InvalidResponseCodeException e) {
      // For POST requests, the underlying network stack will not normally follow 307 or 308
      // redirects automatically. Do so manually here.
      boolean manuallyRedirect =
          (e.responseCode == 307 || e.responseCode == 308)
              && manualRedirectCount++ < MAX_MANUAL_REDIRECTS;
      String redirectUrl = manuallyRedirect ? getRedirectUrl(e) : null;
      if (redirectUrl == null) {
        throw e;
      }
      url = redirectUrl;
    } finally {
      Util.closeQuietly(inputStream);
    }
  }
}
 
Example 4
Source File: PlayerActivity.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "LeafPic"), bandwidthMeter);
}
 
Example 5
Source File: PlayerActivity.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
private HttpDataSource.Factory buildHttpDataSourceFactory(boolean useBandwidthMeter) {
    return new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "LeafPic"), useBandwidthMeter ? BANDWIDTH_METER : null);
}
 
Example 6
Source File: VideoExoPlayer.java    From TigerVideo with Apache License 2.0 4 votes vote down vote up
private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {

        return new DefaultHttpDataSourceFactory(Util.getUserAgent(mContext, TAG), bandwidthMeter, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
                DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true);
    }
 
Example 7
Source File: MediaSourceFactory.java    From CumulusTV with MIT License 4 votes vote down vote up
public static HttpDataSource.Factory buildHttpDataSourceFactory(Context context,
         DefaultBandwidthMeter bandwidthMeter) {
    String userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
 
Example 8
Source File: MediaSourceFactory.java    From CumulusTV with MIT License 4 votes vote down vote up
private static HttpDataSource.Factory buildHttpDataSourceFactory(Context context,
         boolean useBandwidthMeter) {
    return buildHttpDataSourceFactory(context, useBandwidthMeter ? BANDWIDTH_METER : null);
}
 
Example 9
Source File: DemoApplication.java    From TubiPlayer with MIT License 4 votes vote down vote up
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
 
Example 10
Source File: MediaHelper.java    From TubiPlayer with MIT License 4 votes vote down vote up
public static
@NonNull
HttpDataSource.Factory buildHttpDataSourceFactory(@NonNull Context context,
        @NonNull DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(Util.getUserAgent(context, "TubiExoPlayer"), bandwidthMeter);
}
 
Example 11
Source File: MediaSourceCreator.java    From ExoVideoView with Apache License 2.0 4 votes vote down vote up
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
 
Example 12
Source File: HttpMediaDrmCallback.java    From MediaSDK with Apache License 2.0 3 votes vote down vote up
/**
 * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
 *     their own license URL, or for all key requests if {@code forceDefaultLicenseUrl} is
 *     set to true.
 * @param forceDefaultLicenseUrl Whether to use {@code defaultLicenseUrl} for key requests that
 *     include their own license URL.
 * @param dataSourceFactory A factory from which to obtain {@link HttpDataSource} instances.
 */
public HttpMediaDrmCallback(String defaultLicenseUrl, boolean forceDefaultLicenseUrl,
    HttpDataSource.Factory dataSourceFactory) {
  this.dataSourceFactory = dataSourceFactory;
  this.defaultLicenseUrl = defaultLicenseUrl;
  this.forceDefaultLicenseUrl = forceDefaultLicenseUrl;
  this.keyRequestProperties = new HashMap<>();
}
 
Example 13
Source File: HttpMediaDrmCallback.java    From Telegram-FOSS with GNU General Public License v2.0 3 votes vote down vote up
/**
 * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
 *     their own license URL, or for all key requests if {@code forceDefaultLicenseUrl} is
 *     set to true.
 * @param forceDefaultLicenseUrl Whether to use {@code defaultLicenseUrl} for key requests that
 *     include their own license URL.
 * @param dataSourceFactory A factory from which to obtain {@link HttpDataSource} instances.
 */
public HttpMediaDrmCallback(String defaultLicenseUrl, boolean forceDefaultLicenseUrl,
    HttpDataSource.Factory dataSourceFactory) {
  this.dataSourceFactory = dataSourceFactory;
  this.defaultLicenseUrl = defaultLicenseUrl;
  this.forceDefaultLicenseUrl = forceDefaultLicenseUrl;
  this.keyRequestProperties = new HashMap<>();
}
 
Example 14
Source File: LiveVideoPlayerActivity.java    From LiveVideoBroadcaster with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a new HttpDataSource factory.
 *
 * @param useBandwidthMeter Whether to set {@link #BANDWIDTH_METER} as a listener to the new
 *     DataSource factory.
 * @return A new HttpDataSource factory.
 */
private HttpDataSource.Factory buildHttpDataSourceFactory(boolean useBandwidthMeter) {
  return buildHttpDataSourceFactory(useBandwidthMeter ? BANDWIDTH_METER : null);
}
 
Example 15
Source File: HttpMediaDrmCallback.java    From MediaSDK with Apache License 2.0 2 votes vote down vote up
/**
 * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
 *     their own license URL.
 * @param dataSourceFactory A factory from which to obtain {@link HttpDataSource} instances.
 */
public HttpMediaDrmCallback(String defaultLicenseUrl, HttpDataSource.Factory dataSourceFactory) {
  this(defaultLicenseUrl, false, dataSourceFactory);
}
 
Example 16
Source File: PlayerActivity.java    From ExoPlayer-Offline with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a new HttpDataSource factory.
 *
 * @param useBandwidthMeter Whether to set {@link #BANDWIDTH_METER} as a listener to the new
 *                          DataSource factory.
 * @return A new HttpDataSource factory.
 */
private HttpDataSource.Factory buildHttpDataSourceFactory(boolean useBandwidthMeter) {
    return ((DemoApplication) getApplication())
            .buildHttpDataSourceFactory(useBandwidthMeter ? BANDWIDTH_METER : null);
}
 
Example 17
Source File: HttpMediaDrmCallback.java    From K-Sonic with MIT License 2 votes vote down vote up
/**
 * @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);
}
 
Example 18
Source File: HttpMediaDrmCallback.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
 *     their own license URL.
 * @param dataSourceFactory A factory from which to obtain {@link HttpDataSource} instances.
 */
public HttpMediaDrmCallback(String defaultLicenseUrl, HttpDataSource.Factory dataSourceFactory) {
  this(defaultLicenseUrl, false, dataSourceFactory);
}
 
Example 19
Source File: MediaPlayerFragment.java    From PowerFileExplorer with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns a new HttpDataSource factory.
 *
 * @param useBandwidthMeter Whether to set {@link #BANDWIDTH_METER} as a listener to the new
 *     DataSource factory.
 * @return A new HttpDataSource factory.
 */
private HttpDataSource.Factory buildHttpDataSourceFactory(boolean useBandwidthMeter) {
	return ((ExplorerApplication)fragActivity.getApplication())
		.buildHttpDataSourceFactory(useBandwidthMeter ? BANDWIDTH_METER : null);
}
 
Example 20
Source File: HttpMediaDrmCallback.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
 *     their own license URL.
 * @param dataSourceFactory A factory from which to obtain {@link HttpDataSource} instances.
 */
public HttpMediaDrmCallback(String defaultLicenseUrl, HttpDataSource.Factory dataSourceFactory) {
  this(defaultLicenseUrl, false, dataSourceFactory);
}