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

项目:ExoPlayer-Offline    文件:CustomDrmCallback.java   
private byte[] executePost(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   
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);
  }
}
项目:no-player    文件:ExoPlayerErrorMapper.java   
static NoPlayer.PlayerError errorFor(Exception e) {
    if (e instanceof HttpDataSource.InvalidResponseCodeException) {
        return new NoPlayerError(PlayerErrorType.INVALID_RESPONSE_CODE, formatMessage(e));
    }

    if (e instanceof ParserException) {
        return new NoPlayerError(PlayerErrorType.MALFORMED_CONTENT, formatMessage(e));
    }

    Throwable cause = e.getCause();
    if (e.getCause() instanceof MediaCodec.CryptoException) {
        return new NoPlayerError(PlayerErrorType.FAILED_DRM_DECRYPTION, formatMessage(e));
    }

    if (cause instanceof StreamingModularDrm.DrmRequestException) {
        return new NoPlayerError(PlayerErrorType.FAILED_DRM_REQUEST, formatMessage(e));
    }

    if (e instanceof IOException || cause instanceof IOException) {
        return new NoPlayerError(PlayerErrorType.CONNECTIVITY_ERROR, cause == null ? formatMessage(e) : formatMessage(cause));
    }
    return new NoPlayerError(PlayerErrorType.UNKNOWN, formatMessage(e));
}
项目: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);
  }
}
项目:videoPickPlayer    文件:HttpMediaDrmCallback.java   
private byte[] executePost(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 {
    inputStream.close();
  }
}
项目:transistor    文件: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);
  }
}
项目:zapp    文件:VideoErrorHandler.java   
@Override
public void onLoadError(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded, IOException error, boolean wasCanceled) {
    // TODO: test with invalid stream url
    if (!wasCanceled) {
        if (error instanceof HttpDataSource.HttpDataSourceException) {
            listener.onVideoError(R.string.error_stream_io);
        } else {
            listener.onVideoError(R.string.error_stream_unknown);
        }
    }
}
项目: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);
  }
}
项目:K-Sonic    文件:OfflineLicenseHelper.java   
/**
 * Downloads an offline license.
 *
 * @param dataSource The {@link HttpDataSource} to be used for download.
 * @param dashManifest The {@link DashManifest} of the DASH content.
 * @return The downloaded offline license key set id.
 * @throws IOException If an error occurs reading data from the stream.
 * @throws InterruptedException If the thread has been interrupted.
 * @throws DrmSessionException Thrown when there is an error during DRM session.
 */
public byte[] download(HttpDataSource dataSource, DashManifest dashManifest)
    throws IOException, InterruptedException, DrmSessionException {
  // Get DrmInitData
  // Prefer drmInitData obtained from the manifest over drmInitData obtained from the stream,
  // as per DASH IF Interoperability Recommendations V3.0, 7.5.3.
  if (dashManifest.getPeriodCount() < 1) {
    return null;
  }
  Period period = dashManifest.getPeriod(0);
  int adaptationSetIndex = period.getAdaptationSetIndex(C.TRACK_TYPE_VIDEO);
  if (adaptationSetIndex == C.INDEX_UNSET) {
    adaptationSetIndex = period.getAdaptationSetIndex(C.TRACK_TYPE_AUDIO);
    if (adaptationSetIndex == C.INDEX_UNSET) {
      return null;
    }
  }
  AdaptationSet adaptationSet = period.adaptationSets.get(adaptationSetIndex);
  if (adaptationSet.representations.isEmpty()) {
    return null;
  }
  Representation representation = adaptationSet.representations.get(0);
  DrmInitData drmInitData = representation.format.drmInitData;
  if (drmInitData == null) {
    Format sampleFormat = DashUtil.loadSampleFormat(dataSource, representation);
    if (sampleFormat != null) {
      drmInitData = sampleFormat.drmInitData;
    }
    if (drmInitData == null) {
      return null;
    }
  }
  blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, null, drmInitData);
  return drmSessionManager.getOfflineLicenseKeySetId();
}
项目:videoPickPlayer    文件:HttpMediaDrmCallback.java   
/**
 * @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.
 */
public HttpMediaDrmCallback(String defaultUrl, HttpDataSource.Factory dataSourceFactory,
    Map<String, String> keyRequestProperties) {
  this.dataSourceFactory = dataSourceFactory;
  this.defaultUrl = defaultUrl;
  this.keyRequestProperties = keyRequestProperties;
}
项目:transistor    文件:CronetDataSourceFactory.java   
@Override
protected HttpDataSource createDataSourceInternal(HttpDataSource.RequestProperties
    defaultRequestProperties) {
  CronetEngine cronetEngine = cronetEngineWrapper.getCronetEngine();
  if (cronetEngine == null) {
    return fallbackFactory.createDataSource();
  }
  return new CronetDataSource(cronetEngine, executor, contentTypePredicate, transferListener,
      connectTimeoutMs, readTimeoutMs, resetTimeoutOnRedirects, defaultRequestProperties);
}
项目:transistor    文件:CronetDataSourceTest.java   
@Test
public void testRequestOpenValidatesStatusCode() {
  mockResponseStartSuccess();
  testUrlResponseInfo = createUrlResponseInfo(500); // statusCode

  try {
    dataSourceUnderTest.open(testDataSpec);
    fail("HttpDataSource.HttpDataSourceException expected");
  } catch (HttpDataSourceException e) {
    assertTrue(e instanceof HttpDataSource.InvalidResponseCodeException);
    // Check for connection not automatically closed.
    verify(mockUrlRequest, never()).cancel();
    verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec);
  }
}
项目:transistor    文件:CronetDataSourceTest.java   
@Test
public void testRequestOpenValidatesContentTypePredicate() {
  mockResponseStartSuccess();
  when(mockContentTypePredicate.evaluate(anyString())).thenReturn(false);

  try {
    dataSourceUnderTest.open(testDataSpec);
    fail("HttpDataSource.HttpDataSourceException expected");
  } catch (HttpDataSourceException e) {
    assertTrue(e instanceof HttpDataSource.InvalidContentTypeException);
    // Check for connection not automatically closed.
    verify(mockUrlRequest, never()).cancel();
    verify(mockContentTypePredicate).evaluate(TEST_CONTENT_TYPE);
  }
}
项目:RadioDroid    文件:RadioDataSourceFactory.java   
public RadioDataSourceFactory(@NonNull OkHttpClient httpClient,
                              @NonNull TransferListener<? super HttpDataSource> transferListener,
                              @NonNull IcyDataSource.IcyDataSourceListener dataSourceListener,
                              long retryTimeout,
                              long retryDelay) {
    this.httpClient = httpClient;
    this.transferListener = transferListener;
    this.dataSourceListener = dataSourceListener;
    this.retryTimeout = retryTimeout;
    this.retryDelay = retryDelay;
}
项目:RadioDroid    文件:IcyDataSource.java   
public IcyDataSource(@NonNull OkHttpClient httpClient,
                     @NonNull TransferListener<? super HttpDataSource> listener,
                     @NonNull IcyDataSourceListener dataSourceListener,
                     long timeUntilStopReconnecting,
                     long delayBetweenReconnections) {
    this.httpClient = httpClient;
    this.transferListener = listener;
    this.dataSourceListener = dataSourceListener;
    this.timeUntilStopReconnecting = timeUntilStopReconnecting;
    this.delayBetweenReconnections = delayBetweenReconnections;
}
项目:react-native-videoplayer    文件:DataSourceUtil.java   
private static HttpDataSource.Factory buildHttpDataSourceFactory(Context context, DefaultBandwidthMeter bandwidthMeter) {
    return new OkHttpDataSourceFactory(OkHttpClientProvider.getOkHttpClient(), getUserAgent(context), bandwidthMeter);
}
项目:Phoenix-for-VK    文件:CustomHttpDataSourceFactory.java   
@Override
protected CustomHttpDataSource createDataSourceInternal(HttpDataSource.RequestProperties defaultRequestProperties) {
    return new CustomHttpDataSource(userAgent, null, listener, connectTimeoutMillis, readTimeoutMillis, allowCrossProtocolRedirects, defaultRequestProperties, proxy);
}
项目:TubiPlayer    文件:DemoApplication.java   
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
项目:TubiPlayer    文件:MediaHelper.java   
public static
@NonNull
HttpDataSource.Factory buildHttpDataSourceFactory(@NonNull Context context, @NonNull DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(Util.getUserAgent(context, "TubiExoPlayer"), bandwidthMeter);
}
项目:TubiPlayer    文件:TubiPlayerActivity.java   
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "TubiPlayerActivity"), bandwidthMeter);
}
项目:ExoPlayer-Offline    文件:DemoApplication.java   
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
//    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
    return new OkHttpDataSourceFactory(okHttpClient,userAgent,bandwidthMeter);
  }
项目:Android-app    文件:TgbApp.java   
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(deviceIdentifier, bandwidthMeter);
}
项目:chaosflix-leanback    文件:PlayerActivity.java   
private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(mUserAgent, bandwidthMeter,
            DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
            DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
            true /* allowCrossProtocolRedirects */);
}
项目:chaosflix    文件:ExoPlayerFragment.java   
private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(mUserAgent, bandwidthMeter);
}
项目:chaosflix    文件:PlayerActivity.java   
private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(mUserAgent, bandwidthMeter,
            DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
            DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
            true /* allowCrossProtocolRedirects */);
}
项目:nuclei-android    文件:ExoPlayerPlayback.java   
protected HttpDataSource.Factory buildHttpDataSourceFactory(Context context, boolean useBandwidthMeter) {
    final String userAgent = Util.getUserAgent(context, "NucleiPlayer");
    return new DefaultHttpDataSourceFactory(userAgent, useBandwidthMeter ? BANDWIDTH_METER : null, 15000, 15000, false);
}
项目:TigerVideo    文件:VideoExoPlayer.java   
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);
    }
项目:ExoPlayerVideoView    文件:ExoVideoView.java   
HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(Util.getUserAgent(getContext().getApplicationContext(), "ExoVideoView"), bandwidthMeter);
}
项目:cpe-manifest-android-experience    文件:ECVideoViewFragment.java   
private HttpDataSource.Factory buildHttpDataSourceFactory(boolean useBandwidthMeter) {
    String userAgent = Util.getUserAgent(getActivity(), "NextGenExoPlayer");
    DefaultBandwidthMeter bandwidthMeter = useBandwidthMeter ? BANDWIDTH_METER : null;
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
项目:cpe-manifest-android-experience    文件:StartupActivity.java   
private HttpDataSource.Factory buildHttpDataSourceFactory(boolean useBandwidthMeter) {
    String userAgent = Util.getUserAgent(this, "NextGenExoPlayer");
    DefaultBandwidthMeter bandwidthMeter = useBandwidthMeter ? BANDWIDTH_METER : null;
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
项目:MDVideo    文件:PlayerActivityV2.java   
HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "MDVideo"), bandwidthMeter);
}
项目:videoPickPlayer    文件:ExoApplication.java   
HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
项目:Komica    文件:KomicaApplication.java   
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
项目:projectBlue    文件:DiskFileCacheDataSource.java   
public DiskFileCacheDataSource(HttpDataSource defaultHttpDataSource, ICacheStreamSupplier cacheStreamSupplier) {
    this.defaultHttpDataSource = defaultHttpDataSource;
    this.cacheStreamSupplier = cacheStreamSupplier;
}
项目:ExoMedia    文件:ExoMedia.java   
@NonNull
HttpDataSource.BaseFactory provide(@NonNull String userAgent, @Nullable TransferListener<? super DataSource> listener);
项目:transistor    文件:DemoApplication.java   
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
  return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
项目:transistor    文件:OkHttpDataSourceFactory.java   
@Override
protected OkHttpDataSource createDataSourceInternal(
    HttpDataSource.RequestProperties defaultRequestProperties) {
  return new OkHttpDataSource(callFactory, userAgent, null, listener, cacheControl,
      defaultRequestProperties);
}
项目:CumulusTV    文件:MediaSourceFactory.java   
private static HttpDataSource.Factory buildHttpDataSourceFactory(Context context,
         boolean useBandwidthMeter) {
    return buildHttpDataSourceFactory(context, useBandwidthMeter ? BANDWIDTH_METER : null);
}
项目:CumulusTV    文件:MediaSourceFactory.java   
public static HttpDataSource.Factory buildHttpDataSourceFactory(Context context,
         DefaultBandwidthMeter bandwidthMeter) {
    String userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}