public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSource
HttpDataSource that uses Android's HttpURLConnection.
By default this implementation will not follow cross-protocol redirects (i.e. redirects from
HTTP to HTTPS or vice versa). Cross-protocol redirects can be enabled by passing true to
DefaultHttpDataSource.Factory.setAllowCrossProtocolRedirects(boolean).
Note: HTTP request headers will be set using all parameters passed via (in order of decreasing
priority) the dataSpec, setRequestProperty(java.lang.String, java.lang.String) and the default properties that can
be passed to HttpDataSource.Factory.setDefaultRequestProperties(Map).
| 限定符和类型 | 类和说明 |
|---|---|
static class |
DefaultHttpDataSource.Factory
DataSource.Factory for DefaultHttpDataSource instances. |
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_CONNECT_TIMEOUT_MILLIS
The default connection timeout, in milliseconds.
|
static int |
DEFAULT_READ_TIMEOUT_MILLIS
The default read timeout, in milliseconds.
|
| 构造器和说明 |
|---|
DefaultHttpDataSource()
已过时。
Use
DefaultHttpDataSource.Factory instead. |
DefaultHttpDataSource(java.lang.String userAgent)
已过时。
Use
DefaultHttpDataSource.Factory instead. |
DefaultHttpDataSource(java.lang.String userAgent,
int connectTimeoutMillis,
int readTimeoutMillis)
已过时。
Use
DefaultHttpDataSource.Factory instead. |
DefaultHttpDataSource(java.lang.String userAgent,
int connectTimeoutMillis,
int readTimeoutMillis,
boolean allowCrossProtocolRedirects,
HttpDataSource.RequestProperties defaultRequestProperties)
已过时。
Use
DefaultHttpDataSource.Factory instead. |
| 限定符和类型 | 方法和说明 |
|---|---|
protected long |
bytesRead()
Returns the number of bytes that have been read since the most recent call to
open(DataSpec). |
protected long |
bytesRemaining()
Returns the number of bytes that are still to be read for the current
DataSpec. |
protected long |
bytesSkipped()
Returns the number of bytes that have been skipped since the most recent call to
open(DataSpec). |
void |
clearAllRequestProperties()
Clears all request headers that were set by
HttpDataSource.setRequestProperty(String, String). |
void |
clearRequestProperty(java.lang.String name)
Clears the value of a request header.
|
void |
close()
Closes the source.
|
protected java.net.HttpURLConnection |
getConnection()
Returns the current connection, or null if the source is not currently opened.
|
int |
getResponseCode()
When the source is open, returns the HTTP response status code associated with the last
HttpDataSource.open(tv.danmaku.ijk.media.drm.upstream.DataSpec) call. |
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getResponseHeaders()
When the source is open, returns the response headers associated with the last
DataSource.open(tv.danmaku.ijk.media.drm.upstream.DataSpec)
call. |
android.net.Uri |
getUri()
When the source is open, returns the
Uri from which data is being read. |
long |
open(DataSpec dataSpec)
Opens the source to read the specified data.
|
int |
read(byte[] buffer,
int offset,
int readLength)
Reads up to
length bytes of data from the input. |
void |
setContentTypePredicate(java.lang.String contentTypePredicate)
已过时。
|
void |
setRequestProperty(java.lang.String name,
java.lang.String value)
Sets the value of a request header.
|
addTransferListener, bytesTransferred, transferEnded, transferInitializing, transferStartedclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddTransferListenerpublic static final int DEFAULT_CONNECT_TIMEOUT_MILLIS
public static final int DEFAULT_READ_TIMEOUT_MILLIS
@Deprecated public DefaultHttpDataSource()
DefaultHttpDataSource.Factory instead.@Deprecated public DefaultHttpDataSource(java.lang.String userAgent)
DefaultHttpDataSource.Factory instead.@Deprecated
public DefaultHttpDataSource(java.lang.String userAgent,
int connectTimeoutMillis,
int readTimeoutMillis)
DefaultHttpDataSource.Factory instead.@Deprecated
public DefaultHttpDataSource(java.lang.String userAgent,
int connectTimeoutMillis,
int readTimeoutMillis,
boolean allowCrossProtocolRedirects,
HttpDataSource.RequestProperties defaultRequestProperties)
DefaultHttpDataSource.Factory instead.@Deprecated public void setContentTypePredicate(java.lang.String contentTypePredicate)
DefaultHttpDataSource.Factory.setContentTypePredicate(String)
instead.public android.net.Uri getUri()
DataSourceUri from which data is being read. The returned
Uri will be identical to the one passed DataSource.open(DataSpec) in the DataSpec
unless redirection has occurred. If redirection has occurred, the Uri after redirection
is returned.getUri 在接口中 DataSourceUri from which data is being read, or null if the source is not open.public int getResponseCode()
HttpDataSourceHttpDataSource.open(tv.danmaku.ijk.media.drm.upstream.DataSpec) call. Otherwise, returns a negative value.getResponseCode 在接口中 HttpDataSourcepublic java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseHeaders()
DataSourceDataSource.open(tv.danmaku.ijk.media.drm.upstream.DataSpec)
call. Otherwise, returns an empty map.
Key look-up in the returned map is case-insensitive.
getResponseHeaders 在接口中 DataSourcegetResponseHeaders 在接口中 HttpDataSourcepublic void setRequestProperty(java.lang.String name,
java.lang.String value)
HttpDataSourceNote: If the same header is set as a default parameter in the HttpDataSource.Factory, then the
header value set with this method should be preferred when connecting with the data source. See
HttpDataSource.open(tv.danmaku.ijk.media.drm.upstream.DataSpec).
setRequestProperty 在接口中 HttpDataSourcename - The name of the header field.value - The value of the field.public void clearRequestProperty(java.lang.String name)
HttpDataSourceclearRequestProperty 在接口中 HttpDataSourcename - The name of the header field.public void clearAllRequestProperties()
HttpDataSourceHttpDataSource.setRequestProperty(String, String).clearAllRequestProperties 在接口中 HttpDataSourcepublic long open(DataSpec dataSpec) throws HttpDataSource.HttpDataSourceException
open 在接口中 DataSourceopen 在接口中 HttpDataSourcedataSpec - Defines the data to be read.DataSpec.length equals C.LENGTH_UNSET) this value
is the resolved length of the request, or C.LENGTH_UNSET if the length is still
unresolved. For all other requests, the value returned will be equal to the request's
DataSpec.length.HttpDataSource.HttpDataSourceExceptionpublic int read(byte[] buffer,
int offset,
int readLength)
throws HttpDataSource.HttpDataSourceException
DataReaderlength bytes of data from the input.
If readLength is zero then 0 is returned. Otherwise, if no data is available because
the end of the opened range has been reached, then C.RESULT_END_OF_INPUT is returned.
Otherwise, the call will block until at least one byte of data has been read and the number of
bytes read is returned.
read 在接口中 DataReaderread 在接口中 HttpDataSourcebuffer - A target array into which data should be written.offset - The offset into the target array at which to write.readLength - The maximum number of bytes to read from the input.C.RESULT_END_OF_INPUT if the input has ended. This
may be less than length because the end of the input (or available data) was
reached, the method was interrupted, or the operation was aborted early for another reason.HttpDataSource.HttpDataSourceExceptionpublic void close()
throws HttpDataSource.HttpDataSourceException
DataSource
Note: This method must be called even if the corresponding call to DataSource.open(DataSpec)
threw an IOException. See DataSource.open(DataSpec) for more details.
close 在接口中 DataSourceclose 在接口中 HttpDataSourceHttpDataSource.HttpDataSourceExceptionprotected final java.net.HttpURLConnection getConnection()
protected final long bytesSkipped()
open(DataSpec).protected final long bytesRead()
open(DataSpec).protected final long bytesRemaining()
DataSpec.
If the total length of the data being read is known, then this length minus bytesRead()
is returned. If the total length is unknown, C.LENGTH_UNSET is returned.
C.LENGTH_UNSET.