You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to send custom headers to our server while streaming media URL. and I have seen this one. #2166
then I implement my own HttpDataSource.Factory to generating instances of DefaultHttpDataSource like the follow code.
does it work?
private static class VHttpDataSourceFactory implements HttpDataSource.Factory {
private final String userAgent;
private final TransferListener<? super DataSource> listener;
private final int connectTimeoutMillis;
private final int readTimeoutMillis;
private final boolean allowCrossProtocolRedirects;
private Map<String, String> mHeaders = null;
/**
* Constructs a DefaultHttpDataSourceFactory. Sets {@link
* DefaultHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link
* DefaultHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
* cross-protocol redirects.
*
* @param userAgent The User-Agent string that should be used.
*/
public VHttpDataSourceFactory(String userAgent) {
this(userAgent, null);
}
/**
* Constructs a DefaultHttpDataSourceFactory. Sets {@link
* DefaultHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link
* DefaultHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
* cross-protocol redirects.
*
* @param userAgent The User-Agent string that should be used.
* @param listener An optional listener.
* @see #VHttpDataSourceFactory(String, TransferListener, int, int, boolean)
*/
public VHttpDataSourceFactory(
String userAgent, TransferListener<? super DataSource> listener) {
this(userAgent, listener, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, false);
}
/**
* @param userAgent The User-Agent string that should be used.
* @param listener An optional listener.
* @param connectTimeoutMillis The connection timeout that should be used when requesting remote
* data, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
* @param readTimeoutMillis The read timeout that should be used when requesting remote data, in
* milliseconds. A timeout of zero is interpreted as an infinite timeout.
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
* to HTTPS and vice versa) are enabled.
*/
public VHttpDataSourceFactory(String userAgent,
TransferListener<? super DataSource> listener, int connectTimeoutMillis,
int readTimeoutMillis, boolean allowCrossProtocolRedirects) {
this.userAgent = userAgent;
this.listener = listener;
this.connectTimeoutMillis = connectTimeoutMillis;
this.readTimeoutMillis = readTimeoutMillis;
this.allowCrossProtocolRedirects = allowCrossProtocolRedirects;
}
public void setHeader(Map<String, String> header) {
this.mHeaders = header;
}
@Override
public DefaultHttpDataSource createDataSource() {
DefaultHttpDataSource defaultHttpDataSource = new DefaultHttpDataSource(userAgent, null, listener, connectTimeoutMillis,
readTimeoutMillis, allowCrossProtocolRedirects);
if (mHeaders != null) {
for (Map.Entry<String, String> entry : mHeaders.entrySet()) {
defaultHttpDataSource.setRequestProperty(entry.getKey(), entry.getValue());
}
}
return defaultHttpDataSource;
}
}`
The text was updated successfully, but these errors were encountered:
It looks like it should work. It's unclear what the question is here? If you've written some code, it's your responsibility to test whether it works (and debug it if not). The purpose of this tracker is not for us to do it for you. #2166 is tracking making this easier; until then you'll have to do something similar to the code you've written above.
I need to send custom headers to our server while streaming media URL. and I have seen this one. #2166
then I implement my own HttpDataSource.Factory to generating instances of DefaultHttpDataSource like the follow code.
does it work?
The text was updated successfully, but these errors were encountered: