diff --git a/extensions/cronet/README.md b/extensions/cronet/README.md index 112ad26bba..bdacfdbd8b 100644 --- a/extensions/cronet/README.md +++ b/extensions/cronet/README.md @@ -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 ## diff --git a/extensions/okhttp/README.md b/extensions/okhttp/README.md index 2f9893fe3b..8a50346ced 100644 --- a/extensions/okhttp/README.md +++ b/extensions/okhttp/README.md @@ -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 ## diff --git a/extensions/rtmp/README.md b/extensions/rtmp/README.md index a34341692b..99e9d25e8e 100644 --- a/extensions/rtmp/README.md +++ b/extensions/rtmp/README.md @@ -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 ## diff --git a/extensions/rtmp/src/main/java/com/google/android/exoplayer2/ext/rtmp/RtmpDataSource.java b/extensions/rtmp/src/main/java/com/google/android/exoplayer2/ext/rtmp/RtmpDataSource.java index f85a1c641c..b44ff7abde 100644 --- a/extensions/rtmp/src/main/java/com/google/android/exoplayer2/ext/rtmp/RtmpDataSource.java +++ b/extensions/rtmp/src/main/java/com/google/android/exoplayer2/ext/rtmp/RtmpDataSource.java @@ -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. + * + *
The default is {@code null}. + * + *
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; diff --git a/extensions/rtmp/src/main/java/com/google/android/exoplayer2/ext/rtmp/RtmpDataSourceFactory.java b/extensions/rtmp/src/main/java/com/google/android/exoplayer2/ext/rtmp/RtmpDataSourceFactory.java index 70455fdd7a..7d05adb18d 100644 --- a/extensions/rtmp/src/main/java/com/google/android/exoplayer2/ext/rtmp/RtmpDataSourceFactory.java +++ b/extensions/rtmp/src/main/java/com/google/android/exoplayer2/ext/rtmp/RtmpDataSourceFactory.java @@ -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;