Update DataSource extension documentation
Also upgrade the RTMP extension to use an inner class for its factory. PiperOrigin-RevId: 381469114
This commit is contained in:
parent
ec9f512fee
commit
6fe2f25fe9
@ -20,36 +20,27 @@ Alternatively, you can clone the ExoPlayer repository and depend on the module
|
|||||||
locally. Instructions for doing this can be found in ExoPlayer's
|
locally. Instructions for doing this can be found in ExoPlayer's
|
||||||
[top level README][].
|
[top level README][].
|
||||||
|
|
||||||
Note that by default, the extension will use the Cronet implementation in
|
By default, the extension will use the Cronet implementation in Google Play
|
||||||
Google Play Services. If you prefer, it's also possible to embed the Cronet
|
Services. If you prefer, it's also possible to embed the Cronet implementation
|
||||||
implementation directly into your application. See below for more details.
|
directly into your application. See below for more details.
|
||||||
|
|
||||||
[top level README]: https://github.com/google/ExoPlayer/blob/release-v2/README.md
|
[top level README]: https://github.com/google/ExoPlayer/blob/release-v2/README.md
|
||||||
|
|
||||||
## Using the extension ##
|
## Using the extension ##
|
||||||
|
|
||||||
ExoPlayer requests data through `DataSource` instances. These instances are
|
ExoPlayer requests data through `DataSource` instances. These instances are
|
||||||
either instantiated and injected from application code, or obtained from
|
obtained from instances of `DataSource.Factory`, which are instantiated and
|
||||||
instances of `DataSource.Factory` that are instantiated and injected from
|
injected from application code.
|
||||||
application code.
|
|
||||||
|
|
||||||
If your application only needs to play http(s) content, using the Cronet
|
If your application only needs to play http(s) content, using the Cronet
|
||||||
extension is as simple as updating any `DataSource`s and `DataSource.Factory`
|
extension is as simple as updating `DataSource.Factory` instantiations in your
|
||||||
instantiations in your application code to use `CronetDataSource` and
|
application code to use `CronetDataSource.Factory`. If your application also
|
||||||
`CronetDataSourceFactory` respectively. If your application also needs to play
|
needs to play non-http(s) content such as local files, use:
|
||||||
non-http(s) content such as local files, use
|
|
||||||
```
|
|
||||||
new DefaultDataSource(
|
|
||||||
...
|
|
||||||
new CronetDataSource(...) /* baseDataSource argument */);
|
|
||||||
```
|
|
||||||
and
|
|
||||||
```
|
```
|
||||||
new DefaultDataSourceFactory(
|
new DefaultDataSourceFactory(
|
||||||
...
|
...
|
||||||
new CronetDataSourceFactory(...) /* baseDataSourceFactory argument */);
|
/* baseDataSourceFactory= */ new CronetDataSource.Factory(...) );
|
||||||
```
|
```
|
||||||
respectively.
|
|
||||||
|
|
||||||
## Choosing between Google Play Services Cronet and Cronet Embedded ##
|
## Choosing between Google Play Services Cronet and Cronet Embedded ##
|
||||||
|
|
||||||
|
@ -34,27 +34,18 @@ locally. Instructions for doing this can be found in ExoPlayer's
|
|||||||
## Using the extension ##
|
## Using the extension ##
|
||||||
|
|
||||||
ExoPlayer requests data through `DataSource` instances. These instances are
|
ExoPlayer requests data through `DataSource` instances. These instances are
|
||||||
either instantiated and injected from application code, or obtained from
|
obtained from instances of `DataSource.Factory`, which are instantiated and
|
||||||
instances of `DataSource.Factory` that are instantiated and injected from
|
injected from application code.
|
||||||
application code.
|
|
||||||
|
|
||||||
If your application only needs to play http(s) content, using the OkHttp
|
If your application only needs to play http(s) content, using the OkHttp
|
||||||
extension is as simple as updating any `DataSource`s and `DataSource.Factory`
|
extension is as simple as updating any `DataSource.Factory` instantiations in
|
||||||
instantiations in your application code to use `OkHttpDataSource` and
|
your application code to use `OkHttpDataSource.Factory`. If your application
|
||||||
`OkHttpDataSourceFactory` respectively. If your application also needs to play
|
also needs to play non-http(s) content such as local files, use:
|
||||||
non-http(s) content such as local files, use
|
|
||||||
```
|
|
||||||
new DefaultDataSource(
|
|
||||||
...
|
|
||||||
new OkHttpDataSource(...) /* baseDataSource argument */);
|
|
||||||
```
|
|
||||||
and
|
|
||||||
```
|
```
|
||||||
new DefaultDataSourceFactory(
|
new DefaultDataSourceFactory(
|
||||||
...
|
...
|
||||||
new OkHttpDataSourceFactory(...) /* baseDataSourceFactory argument */);
|
/* baseDataSourceFactory= */ new OkHttpDataSource.Factory(...));
|
||||||
```
|
```
|
||||||
respectively.
|
|
||||||
|
|
||||||
## Links ##
|
## Links ##
|
||||||
|
|
||||||
|
@ -35,18 +35,17 @@ locally. Instructions for doing this can be found in ExoPlayer's
|
|||||||
## Using the extension ##
|
## Using the extension ##
|
||||||
|
|
||||||
ExoPlayer requests data through `DataSource` instances. These instances are
|
ExoPlayer requests data through `DataSource` instances. These instances are
|
||||||
either instantiated and injected from application code, or obtained from
|
obtained from instances of `DataSource.Factory`, which are instantiated and
|
||||||
instances of `DataSource.Factory` that are instantiated and injected from
|
injected from application code.
|
||||||
application code.
|
|
||||||
|
|
||||||
`DefaultDataSource` will automatically use the RTMP extension whenever it's
|
`DefaultDataSource` will automatically use the RTMP extension whenever it's
|
||||||
available. Hence if your application is using `DefaultDataSource` or
|
available. Hence if your application is using `DefaultDataSource` or
|
||||||
`DefaultDataSourceFactory`, adding support for RTMP streams is as simple as
|
`DefaultDataSourceFactory`, adding support for RTMP streams is as simple as
|
||||||
adding a dependency to the RTMP extension as described above. No changes to your
|
adding a dependency to the RTMP extension as described above. No changes to your
|
||||||
application code are required. Alternatively, if you know that your application
|
application code are required. Alternatively, if you know that your application
|
||||||
doesn't need to handle any other protocols, you can update any `DataSource`s and
|
doesn't need to handle any other protocols, you can update any
|
||||||
`DataSource.Factory` instantiations in your application code to use
|
`DataSource.Factory` instantiations in your application code to use
|
||||||
`RtmpDataSource` and `RtmpDataSourceFactory` directly.
|
`RtmpDataSource.Factory` directly.
|
||||||
|
|
||||||
## Links ##
|
## Links ##
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
|||||||
import com.google.android.exoplayer2.upstream.BaseDataSource;
|
import com.google.android.exoplayer2.upstream.BaseDataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DataSpec;
|
import com.google.android.exoplayer2.upstream.DataSpec;
|
||||||
|
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import net.butterflytv.rtmp_client.RtmpClient;
|
import net.butterflytv.rtmp_client.RtmpClient;
|
||||||
import net.butterflytv.rtmp_client.RtmpClient.RtmpIOException;
|
import net.butterflytv.rtmp_client.RtmpClient.RtmpIOException;
|
||||||
@ -35,6 +36,36 @@ public final class RtmpDataSource extends BaseDataSource {
|
|||||||
ExoPlayerLibraryInfo.registerModule("goog.exo.rtmp");
|
ExoPlayerLibraryInfo.registerModule("goog.exo.rtmp");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@link DataSource.Factory} for {@link RtmpDataSource} instances. */
|
||||||
|
public static final class Factory implements DataSource.Factory {
|
||||||
|
|
||||||
|
@Nullable private TransferListener transferListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@link TransferListener} that will be used.
|
||||||
|
*
|
||||||
|
* <p>The default is {@code null}.
|
||||||
|
*
|
||||||
|
* <p>See {@link DataSource#addTransferListener(TransferListener)}.
|
||||||
|
*
|
||||||
|
* @param transferListener The listener that will be used.
|
||||||
|
* @return This factory.
|
||||||
|
*/
|
||||||
|
public Factory setTransferListener(@Nullable TransferListener transferListener) {
|
||||||
|
this.transferListener = transferListener;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RtmpDataSource createDataSource() {
|
||||||
|
RtmpDataSource dataSource = new RtmpDataSource();
|
||||||
|
if (transferListener != null) {
|
||||||
|
dataSource.addTransferListener(transferListener);
|
||||||
|
}
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable private RtmpClient rtmpClient;
|
@Nullable private RtmpClient rtmpClient;
|
||||||
@Nullable private Uri uri;
|
@Nullable private Uri uri;
|
||||||
|
|
||||||
|
@ -17,10 +17,10 @@ package com.google.android.exoplayer2.ext.rtmp;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
|
|
||||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||||
|
|
||||||
/** A {@link Factory} that produces {@link RtmpDataSource}. */
|
/** @deprecated Use {@link RtmpDataSource.Factory} instead. */
|
||||||
|
@Deprecated
|
||||||
public final class RtmpDataSourceFactory implements DataSource.Factory {
|
public final class RtmpDataSourceFactory implements DataSource.Factory {
|
||||||
|
|
||||||
@Nullable private final TransferListener listener;
|
@Nullable private final TransferListener listener;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user