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); } }
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); } }
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)); }
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(); } }
/** * @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); } }
@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); } } }
/** * 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(); }
/** * @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; }
@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); }
@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); } }
@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); } }
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; }
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; }
private static HttpDataSource.Factory buildHttpDataSourceFactory(Context context, DefaultBandwidthMeter bandwidthMeter) { return new OkHttpDataSourceFactory(OkHttpClientProvider.getOkHttpClient(), getUserAgent(context), bandwidthMeter); }
@Override protected CustomHttpDataSource createDataSourceInternal(HttpDataSource.RequestProperties defaultRequestProperties) { return new CustomHttpDataSource(userAgent, null, listener, connectTimeoutMillis, readTimeoutMillis, allowCrossProtocolRedirects, defaultRequestProperties, proxy); }
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) { return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter); }
public static @NonNull HttpDataSource.Factory buildHttpDataSourceFactory(@NonNull Context context, @NonNull DefaultBandwidthMeter bandwidthMeter) { return new DefaultHttpDataSourceFactory(Util.getUserAgent(context, "TubiExoPlayer"), bandwidthMeter); }
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) { return new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "TubiPlayerActivity"), bandwidthMeter); }
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) { // return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter); return new OkHttpDataSourceFactory(okHttpClient,userAgent,bandwidthMeter); }
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) { return new DefaultHttpDataSourceFactory(deviceIdentifier, bandwidthMeter); }
private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) { return new DefaultHttpDataSourceFactory(mUserAgent, bandwidthMeter, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true /* allowCrossProtocolRedirects */); }
private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) { return new DefaultHttpDataSourceFactory(mUserAgent, bandwidthMeter); }
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); }
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); }
HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) { return new DefaultHttpDataSourceFactory(Util.getUserAgent(getContext().getApplicationContext(), "ExoVideoView"), bandwidthMeter); }
private HttpDataSource.Factory buildHttpDataSourceFactory(boolean useBandwidthMeter) { String userAgent = Util.getUserAgent(getActivity(), "NextGenExoPlayer"); DefaultBandwidthMeter bandwidthMeter = useBandwidthMeter ? BANDWIDTH_METER : null; return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter); }
private HttpDataSource.Factory buildHttpDataSourceFactory(boolean useBandwidthMeter) { String userAgent = Util.getUserAgent(this, "NextGenExoPlayer"); DefaultBandwidthMeter bandwidthMeter = useBandwidthMeter ? BANDWIDTH_METER : null; return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter); }
HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) { return new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "MDVideo"), bandwidthMeter); }
HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) { return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter); }
public DiskFileCacheDataSource(HttpDataSource defaultHttpDataSource, ICacheStreamSupplier cacheStreamSupplier) { this.defaultHttpDataSource = defaultHttpDataSource; this.cacheStreamSupplier = cacheStreamSupplier; }
@NonNull HttpDataSource.BaseFactory provide(@NonNull String userAgent, @Nullable TransferListener<? super DataSource> listener);
@Override protected OkHttpDataSource createDataSourceInternal( HttpDataSource.RequestProperties defaultRequestProperties) { return new OkHttpDataSource(callFactory, userAgent, null, listener, cacheControl, defaultRequestProperties); }
private static HttpDataSource.Factory buildHttpDataSourceFactory(Context context, boolean useBandwidthMeter) { return buildHttpDataSourceFactory(context, useBandwidthMeter ? BANDWIDTH_METER : null); }
public static HttpDataSource.Factory buildHttpDataSourceFactory(Context context, DefaultBandwidthMeter bandwidthMeter) { String userAgent = Util.getUserAgent(context, "ExoPlayerDemo"); return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter); }