Search in sources :

Example 1 with MediaDrmCallbackException

use of com.google.android.exoplayer2.drm.MediaDrmCallbackException in project ExoPlayer by google.

the class HttpMediaDrmCallback method executePost.

private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url, @Nullable byte[] httpBody, Map<String, String> requestProperties) throws MediaDrmCallbackException {
    StatsDataSource dataSource = new StatsDataSource(dataSourceFactory.createDataSource());
    int manualRedirectCount = 0;
    DataSpec dataSpec = new DataSpec.Builder().setUri(url).setHttpRequestHeaders(requestProperties).setHttpMethod(DataSpec.HTTP_METHOD_POST).setHttpBody(httpBody).setFlags(DataSpec.FLAG_ALLOW_GZIP).build();
    DataSpec originalDataSpec = dataSpec;
    try {
        while (true) {
            DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
            try {
                return Util.toByteArray(inputStream);
            } catch (InvalidResponseCodeException e) {
                @Nullable String redirectUrl = getRedirectUrl(e, manualRedirectCount);
                if (redirectUrl == null) {
                    throw e;
                }
                manualRedirectCount++;
                dataSpec = dataSpec.buildUpon().setUri(redirectUrl).build();
            } finally {
                Util.closeQuietly(inputStream);
            }
        }
    } catch (Exception e) {
        throw new MediaDrmCallbackException(originalDataSpec, Assertions.checkNotNull(dataSource.getLastOpenedUri()), dataSource.getResponseHeaders(), dataSource.getBytesRead(), /* cause= */
        e);
    }
}
Also used : StatsDataSource(com.google.android.exoplayer2.upstream.StatsDataSource) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) InvalidResponseCodeException(com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException) InvalidResponseCodeException(com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException) DataSourceInputStream(com.google.android.exoplayer2.upstream.DataSourceInputStream)

Aggregations

DataSourceInputStream (com.google.android.exoplayer2.upstream.DataSourceInputStream)1 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)1 InvalidResponseCodeException (com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException)1 StatsDataSource (com.google.android.exoplayer2.upstream.StatsDataSource)1