Java Code Examples for com.google.android.exoplayer2.upstream.HttpDataSource#setRequestProperty()
The following examples show how to use
com.google.android.exoplayer2.upstream.HttpDataSource#setRequestProperty() .
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: CustomDrmCallback.java From ExoPlayer-Offline with Apache License 2.0 | 6 votes |
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); } }
Example 2
Source File: HttpMediaDrmCallback.java From K-Sonic with MIT License | 6 votes |
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); } }
Example 3
Source File: HttpMediaDrmCallback.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
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()); } } int manualRedirectCount = 0; while (true) { DataSpec dataSpec = new DataSpec( Uri.parse(url), data, /* 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; url = manuallyRedirect ? getRedirectUrl(e) : null; if (url == null) { throw e; } } finally { Util.closeQuietly(inputStream); } } }
Example 4
Source File: HttpMediaDrmCallback.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
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()); } } int manualRedirectCount = 0; while (true) { DataSpec dataSpec = new DataSpec( Uri.parse(url), data, /* 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; url = manuallyRedirect ? getRedirectUrl(e) : null; if (url == null) { throw e; } } finally { Util.closeQuietly(inputStream); } } }
Example 5
Source File: HttpMediaDrmCallback.java From MediaSDK with Apache License 2.0 | 4 votes |
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 6
Source File: HttpMediaDrmCallback.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private static byte[] executePost( HttpDataSource.Factory dataSourceFactory, String url, byte[] data, @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), data, /* 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 7
Source File: HttpMediaDrmCallback.java From Telegram with GNU General Public License v2.0 | 4 votes |
private static byte[] executePost( HttpDataSource.Factory dataSourceFactory, String url, byte[] data, @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), data, /* 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); } } }