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:
olly 2021-06-25 15:43:29 +01:00 committed by Oliver Woodman
parent ec9f512fee
commit 6fe2f25fe9
5 changed files with 52 additions and 40 deletions

View File

@ -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
[top level README][].
Note that by default, the extension will use the Cronet implementation in
Google Play Services. If you prefer, it's also possible to embed the Cronet
implementation directly into your application. See below for more details.
By default, the extension will use the Cronet implementation in Google Play
Services. If you prefer, it's also possible to embed the Cronet implementation
directly into your application. See below for more details.
[top level README]: https://github.com/google/ExoPlayer/blob/release-v2/README.md
## Using the extension ##
ExoPlayer requests data through `DataSource` instances. These instances are
either instantiated and injected from application code, or obtained from
instances of `DataSource.Factory` that are instantiated and injected from
application code.
obtained from instances of `DataSource.Factory`, which are instantiated and
injected from application code.
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`
instantiations in your application code to use `CronetDataSource` and
`CronetDataSourceFactory` respectively. If your application also needs to play
non-http(s) content such as local files, use
```
new DefaultDataSource(
...
new CronetDataSource(...) /* baseDataSource argument */);
```
and
extension is as simple as updating `DataSource.Factory` instantiations in your
application code to use `CronetDataSource.Factory`. If your application also
needs to play non-http(s) content such as local files, use:
```
new DefaultDataSourceFactory(
...
new CronetDataSourceFactory(...) /* baseDataSourceFactory argument */);
/* baseDataSourceFactory= */ new CronetDataSource.Factory(...) );
```
respectively.
## Choosing between Google Play Services Cronet and Cronet Embedded ##

View File

@ -34,27 +34,18 @@ locally. Instructions for doing this can be found in ExoPlayer's
## Using the extension ##
ExoPlayer requests data through `DataSource` instances. These instances are
either instantiated and injected from application code, or obtained from
instances of `DataSource.Factory` that are instantiated and injected from
application code.
obtained from instances of `DataSource.Factory`, which are instantiated and
injected from application code.
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`
instantiations in your application code to use `OkHttpDataSource` and
`OkHttpDataSourceFactory` respectively. If your application also needs to play
non-http(s) content such as local files, use
```
new DefaultDataSource(
...
new OkHttpDataSource(...) /* baseDataSource argument */);
```
and
extension is as simple as updating any `DataSource.Factory` instantiations in
your application code to use `OkHttpDataSource.Factory`. If your application
also needs to play non-http(s) content such as local files, use:
```
new DefaultDataSourceFactory(
...
new OkHttpDataSourceFactory(...) /* baseDataSourceFactory argument */);
/* baseDataSourceFactory= */ new OkHttpDataSource.Factory(...));
```
respectively.
## Links ##

View File

@ -35,18 +35,17 @@ locally. Instructions for doing this can be found in ExoPlayer's
## Using the extension ##
ExoPlayer requests data through `DataSource` instances. These instances are
either instantiated and injected from application code, or obtained from
instances of `DataSource.Factory` that are instantiated and injected from
application code.
obtained from instances of `DataSource.Factory`, which are instantiated and
injected from application code.
`DefaultDataSource` will automatically use the RTMP extension whenever it's
available. Hence if your application is using `DefaultDataSource` or
`DefaultDataSourceFactory`, adding support for RTMP streams is as simple as
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
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
`RtmpDataSource` and `RtmpDataSourceFactory` directly.
`RtmpDataSource.Factory` directly.
## Links ##

View File

@ -24,6 +24,7 @@ import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.upstream.BaseDataSource;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.TransferListener;
import java.io.IOException;
import net.butterflytv.rtmp_client.RtmpClient;
import net.butterflytv.rtmp_client.RtmpClient.RtmpIOException;
@ -35,6 +36,36 @@ public final class RtmpDataSource extends BaseDataSource {
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 Uri uri;

View File

@ -17,10 +17,10 @@ package com.google.android.exoplayer2.ext.rtmp;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
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 {
@Nullable private final TransferListener listener;