diff --git a/demos/main/src/main/java/androidx/media3/demo/main/PlayerActivity.java b/demos/main/src/main/java/androidx/media3/demo/main/PlayerActivity.java index 00cb9e7b26..369af5698e 100644 --- a/demos/main/src/main/java/androidx/media3/demo/main/PlayerActivity.java +++ b/demos/main/src/main/java/androidx/media3/demo/main/PlayerActivity.java @@ -47,7 +47,7 @@ import androidx.media3.exoplayer.mediacodec.MediaCodecRenderer.DecoderInitializa import androidx.media3.exoplayer.mediacodec.MediaCodecUtil.DecoderQueryException; import androidx.media3.exoplayer.offline.DownloadRequest; import androidx.media3.exoplayer.source.DefaultMediaSourceFactory; -import androidx.media3.exoplayer.source.MediaSourceFactory; +import androidx.media3.exoplayer.source.MediaSource; import androidx.media3.exoplayer.source.ads.AdsLoader; import androidx.media3.exoplayer.trackselection.DefaultTrackSelector; import androidx.media3.exoplayer.util.DebugTextViewHelper; @@ -261,7 +261,7 @@ public class PlayerActivity extends AppCompatActivity intent.getBooleanExtra(IntentUtil.PREFER_EXTENSION_DECODERS_EXTRA, false); RenderersFactory renderersFactory = DemoUtil.buildRenderersFactory(/* context= */ this, preferExtensionDecoders); - MediaSourceFactory mediaSourceFactory = + MediaSource.Factory mediaSourceFactory = new DefaultMediaSourceFactory(dataSourceFactory) .setAdsLoaderProvider(this::getAdsLoader) .setAdViewProvider(playerView); diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayer.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayer.java index e9906b1608..7145b4536b 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayer.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayer.java @@ -53,7 +53,6 @@ import androidx.media3.exoplayer.audio.MediaCodecAudioRenderer; import androidx.media3.exoplayer.metadata.MetadataRenderer; import androidx.media3.exoplayer.source.DefaultMediaSourceFactory; import androidx.media3.exoplayer.source.MediaSource; -import androidx.media3.exoplayer.source.MediaSourceFactory; import androidx.media3.exoplayer.source.ShuffleOrder; import androidx.media3.exoplayer.text.TextRenderer; import androidx.media3.exoplayer.trackselection.DefaultTrackSelector; @@ -83,7 +82,7 @@ import java.util.List; *
Use {@link #Builder(Context, RenderersFactory)}, {@link #Builder(Context, - * MediaSourceFactory)} or {@link #Builder(Context, RenderersFactory, MediaSourceFactory)} + * MediaSource.Factory)} or {@link #Builder(Context, RenderersFactory, MediaSource.Factory)} * instead, if you intend to provide a custom {@link RenderersFactory}, {@link * ExtractorsFactory} or {@link DefaultMediaSourceFactory}. This is to ensure that ProGuard or * R8 can remove ExoPlayer's {@link DefaultRenderersFactory}, {@link DefaultExtractorsFactory} @@ -418,7 +417,7 @@ public interface ExoPlayer extends Player { *
See {@link #Builder(Context)} for a list of default values. * @@ -487,12 +486,12 @@ public interface ExoPlayer extends Player { * MediaItem}. */ @UnstableApi - public Builder(Context context, MediaSourceFactory mediaSourceFactory) { + public Builder(Context context, MediaSource.Factory mediaSourceFactory) { this(context, () -> new DefaultRenderersFactory(context), () -> mediaSourceFactory); } /** - * Creates a builder with a custom {@link RenderersFactory} and {@link MediaSourceFactory}. + * Creates a builder with a custom {@link RenderersFactory} and {@link MediaSource.Factory}. * *
See {@link #Builder(Context)} for a list of default values.
*
@@ -508,7 +507,9 @@ public interface ExoPlayer extends Player {
*/
@UnstableApi
public Builder(
- Context context, RenderersFactory renderersFactory, MediaSourceFactory mediaSourceFactory) {
+ Context context,
+ RenderersFactory renderersFactory,
+ MediaSource.Factory mediaSourceFactory) {
this(context, () -> renderersFactory, () -> mediaSourceFactory);
}
@@ -521,7 +522,7 @@ public interface ExoPlayer extends Player {
* @param context A {@link Context}.
* @param renderersFactory A factory for creating {@link Renderer Renderers} to be used by the
* player.
- * @param mediaSourceFactory A {@link MediaSourceFactory}.
+ * @param mediaSourceFactory A {@link MediaSource.Factory}.
* @param trackSelector A {@link TrackSelector}.
* @param loadControl A {@link LoadControl}.
* @param bandwidthMeter A {@link BandwidthMeter}.
@@ -531,7 +532,7 @@ public interface ExoPlayer extends Player {
public Builder(
Context context,
RenderersFactory renderersFactory,
- MediaSourceFactory mediaSourceFactory,
+ MediaSource.Factory mediaSourceFactory,
TrackSelector trackSelector,
LoadControl loadControl,
BandwidthMeter bandwidthMeter,
@@ -549,7 +550,7 @@ public interface ExoPlayer extends Player {
private Builder(
Context context,
Supplier This is equivalent to using {@link #retrieveMetadata(MediaSourceFactory, MediaItem)} with a
+ * This is equivalent to using {@link #retrieveMetadata(MediaSource.Factory, MediaItem)} with a
* {@link DefaultMediaSourceFactory} and a {@link DefaultExtractorsFactory} with {@link
* Mp4Extractor#FLAG_READ_MOTION_PHOTO_METADATA} and {@link Mp4Extractor#FLAG_READ_SEF_DATA} set.
*
@@ -72,13 +71,13 @@ public final class MetadataRetriever {
*
* This method is thread-safe.
*
- * @param mediaSourceFactory mediaSourceFactory The {@link MediaSourceFactory} to use to read the
+ * @param mediaSourceFactory mediaSourceFactory The {@link MediaSource.Factory} to use to read the
* data.
* @param mediaItem The {@link MediaItem} whose metadata should be retrieved.
* @return A {@link ListenableFuture} of the result.
*/
public static ListenableFuture This implementation delegates calls to {@link #createMediaSource(MediaItem)} to the following
* factories:
@@ -93,6 +93,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
* configuration}, {@link #setAdsLoaderProvider} and {@link #setAdViewProvider} need to be called to
* configure the factory with the required providers.
*/
+@SuppressWarnings("deprecation") // Implement deprecated type for backwards compatibility.
public final class DefaultMediaSourceFactory implements MediaSourceFactory {
/** @deprecated Use {@link AdsLoader.Provider} instead. */
@@ -105,7 +106,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
private final DataSource.Factory dataSourceFactory;
private final DelegateFactoryLoader delegateFactoryLoader;
- @Nullable private final MediaSourceFactory serverSideDaiMediaSourceFactory;
+ @Nullable private final MediaSource.Factory serverSideDaiMediaSourceFactory;
@Nullable private AdsLoader.Provider adsLoaderProvider;
@Nullable private AdViewProvider adViewProvider;
@Nullable private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
@@ -161,14 +162,14 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
* for requesting media data.
* @param extractorsFactory An {@link ExtractorsFactory} used to extract progressive media from
* its container.
- * @param serverSideDaiMediaSourceFactory A {@link MediaSourceFactory} for creating server side
+ * @param serverSideDaiMediaSourceFactory A {@link MediaSource.Factory} for creating server side
* inserted ad media sources.
*/
@UnstableApi
public DefaultMediaSourceFactory(
DataSource.Factory dataSourceFactory,
ExtractorsFactory extractorsFactory,
- @Nullable MediaSourceFactory serverSideDaiMediaSourceFactory) {
+ @Nullable MediaSource.Factory serverSideDaiMediaSourceFactory) {
this.dataSourceFactory = dataSourceFactory;
// Temporary until factory registration is agreed upon.
this.serverSideDaiMediaSourceFactory = serverSideDaiMediaSourceFactory;
@@ -324,7 +325,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
Util.inferContentTypeForUriAndMimeType(
mediaItem.localConfiguration.uri, mediaItem.localConfiguration.mimeType);
@Nullable
- MediaSourceFactory mediaSourceFactory = delegateFactoryLoader.getMediaSourceFactory(type);
+ MediaSource.Factory mediaSourceFactory = delegateFactoryLoader.getMediaSourceFactory(type);
checkStateNotNull(
mediaSourceFactory, "No suitable media source factory found for content type: " + type);
@@ -450,10 +451,10 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
private static final class DelegateFactoryLoader {
private final DataSource.Factory dataSourceFactory;
private final ExtractorsFactory extractorsFactory;
- private final Map If not set, {@link DefaultDrmSessionManagerProvider} is used.
+ *
+ * @return This factory, for convenience.
+ */
+ @UnstableApi
+ Factory setDrmSessionManagerProvider(
+ @Nullable DrmSessionManagerProvider drmSessionManagerProvider);
+
+ /**
+ * Sets an optional {@link LoadErrorHandlingPolicy}.
+ *
+ * @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}, or {@code null} to use the
+ * {@link DefaultLoadErrorHandlingPolicy}.
+ * @return This factory, for convenience.
+ */
+ @UnstableApi
+ Factory setLoadErrorHandlingPolicy(@Nullable LoadErrorHandlingPolicy loadErrorHandlingPolicy);
+
+ /**
+ * Returns the {@link C.ContentType content types} supported by media sources created by this
+ * factory.
+ */
+ @UnstableApi
+ @C.ContentType
+ int[] getSupportedTypes();
+
+ /**
+ * Creates a new {@link MediaSource} with the specified {@link MediaItem}.
+ *
+ * @param mediaItem The media item to play.
+ * @return The new {@link MediaSource media source}.
+ */
+ @UnstableApi
+ MediaSource createMediaSource(MediaItem mediaItem);
+ }
+
/** A caller of media sources, which will be notified of source events. */
+ @UnstableApi
interface MediaSourceCaller {
/**
@@ -69,6 +126,7 @@ public interface MediaSource {
*
* Extends for backward-compatibility {@link androidx.media3.common.MediaPeriodId}.
*/
+ @UnstableApi
final class MediaPeriodId extends androidx.media3.common.MediaPeriodId {
/** See {@link androidx.media3.common.MediaPeriodId#MediaPeriodId(Object)}. */
@@ -117,6 +175,7 @@ public interface MediaSource {
* @param handler A handler on the which listener events will be posted.
* @param eventListener The listener to be added.
*/
+ @UnstableApi
void addEventListener(Handler handler, MediaSourceEventListener eventListener);
/**
@@ -125,6 +184,7 @@ public interface MediaSource {
*
* @param eventListener The listener to be removed.
*/
+ @UnstableApi
void removeEventListener(MediaSourceEventListener eventListener);
/**
@@ -134,6 +194,7 @@ public interface MediaSource {
* @param handler A handler on the which listener events will be posted.
* @param eventListener The listener to be added.
*/
+ @UnstableApi
void addDrmEventListener(Handler handler, DrmSessionEventListener eventListener);
/**
@@ -142,6 +203,7 @@ public interface MediaSource {
*
* @param eventListener The listener to be removed.
*/
+ @UnstableApi
void removeDrmEventListener(DrmSessionEventListener eventListener);
/**
@@ -155,6 +217,7 @@ public interface MediaSource {
* Any media source which has multiple windows should typically provide such an initial
* timeline to make sure the player reports the correct number of windows immediately.
*/
+ @UnstableApi
@Nullable
default Timeline getInitialTimeline() {
return null;
@@ -167,17 +230,20 @@ public interface MediaSource {
*
* @return true if the source has exactly one window.
*/
+ @UnstableApi
default boolean isSingleWindow() {
return true;
}
/** Returns the {@link MediaItem} whose media is provided by the source. */
+ @UnstableApi
MediaItem getMediaItem();
/**
* @deprecated Implement {@link #prepareSource(MediaSourceCaller, TransferListener, PlayerId)}
* instead.
*/
+ @UnstableApi
@Deprecated
default void prepareSource(
MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener) {
@@ -203,6 +269,7 @@ public interface MediaSource {
* and other data.
* @param playerId The {@link PlayerId} of the player using this media source.
*/
+ @UnstableApi
void prepareSource(
MediaSourceCaller caller,
@Nullable TransferListener mediaTransferListener,
@@ -216,6 +283,7 @@ public interface MediaSource {
* Must only be called after {@link #prepareSource(MediaSourceCaller, TransferListener,
* PlayerId)}.
*/
+ @UnstableApi
void maybeThrowSourceInfoRefreshError() throws IOException;
/**
@@ -228,6 +296,7 @@ public interface MediaSource {
*
* @param caller The {@link MediaSourceCaller} enabling the source.
*/
+ @UnstableApi
void enable(MediaSourceCaller caller);
/**
@@ -242,6 +311,7 @@ public interface MediaSource {
* @param startPositionUs The expected start position, in microseconds.
* @return A new {@link MediaPeriod}.
*/
+ @UnstableApi
MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs);
/**
@@ -251,6 +321,7 @@ public interface MediaSource {
*
* @param mediaPeriod The period to release.
*/
+ @UnstableApi
void releasePeriod(MediaPeriod mediaPeriod);
/**
@@ -265,6 +336,7 @@ public interface MediaSource {
*
* @param caller The {@link MediaSourceCaller} disabling the source.
*/
+ @UnstableApi
void disable(MediaSourceCaller caller);
/**
@@ -277,5 +349,6 @@ public interface MediaSource {
*
* @param caller The {@link MediaSourceCaller} to be unregistered.
*/
+ @UnstableApi
void releaseSource(MediaSourceCaller caller);
}
diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/MediaSourceFactory.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/MediaSourceFactory.java
index a805fc7845..af34e47388 100644
--- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/MediaSourceFactory.java
+++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/MediaSourceFactory.java
@@ -19,14 +19,13 @@ import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.MediaItem;
import androidx.media3.common.util.UnstableApi;
-import androidx.media3.exoplayer.drm.DefaultDrmSessionManagerProvider;
-import androidx.media3.exoplayer.drm.DrmSessionManager;
import androidx.media3.exoplayer.drm.DrmSessionManagerProvider;
-import androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy;
import androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy;
-/** Factory for creating {@link MediaSource MediaSources} from {@link MediaItem MediaItems}. */
-public interface MediaSourceFactory {
+/** @deprecated Use {@link MediaSource.Factory}. */
+@UnstableApi
+@Deprecated
+public interface MediaSourceFactory extends MediaSource.Factory {
/**
* An instance that throws {@link UnsupportedOperationException} from {@link #createMediaSource}
@@ -58,44 +57,4 @@ public interface MediaSourceFactory {
throw new UnsupportedOperationException();
}
};
-
- /**
- * Sets the {@link DrmSessionManagerProvider} used to obtain a {@link DrmSessionManager} for a
- * {@link MediaItem}.
- *
- * If not set, {@link DefaultDrmSessionManagerProvider} is used.
- *
- * @return This factory, for convenience.
- */
- @UnstableApi
- MediaSourceFactory setDrmSessionManagerProvider(
- @Nullable DrmSessionManagerProvider drmSessionManagerProvider);
-
- /**
- * Sets an optional {@link LoadErrorHandlingPolicy}.
- *
- * @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}, or {@code null} to use the
- * {@link DefaultLoadErrorHandlingPolicy}.
- * @return This factory, for convenience.
- */
- @UnstableApi
- MediaSourceFactory setLoadErrorHandlingPolicy(
- @Nullable LoadErrorHandlingPolicy loadErrorHandlingPolicy);
-
- /**
- * Returns the {@link C.ContentType content types} supported by media sources created by this
- * factory.
- */
- @UnstableApi
- @C.ContentType
- int[] getSupportedTypes();
-
- /**
- * Creates a new {@link MediaSource} with the specified {@link MediaItem}.
- *
- * @param mediaItem The media item to play.
- * @return The new {@link MediaSource media source}.
- */
- @UnstableApi
- MediaSource createMediaSource(MediaItem mediaItem);
}
diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaSource.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaSource.java
index 14b6f8e3f0..e0614f4789 100644
--- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaSource.java
+++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaSource.java
@@ -52,6 +52,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
implements ProgressiveMediaPeriod.Listener {
/** Factory for {@link ProgressiveMediaSource}s. */
+ @SuppressWarnings("deprecation") // Implement deprecated type for backwards compatibility.
public static final class Factory implements MediaSourceFactory {
private final DataSource.Factory dataSourceFactory;
diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ads/AdsMediaSource.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ads/AdsMediaSource.java
index 4b6c064ae5..7cb73edc6f 100644
--- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ads/AdsMediaSource.java
+++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ads/AdsMediaSource.java
@@ -42,7 +42,6 @@ import androidx.media3.exoplayer.source.MediaPeriod;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.exoplayer.source.MediaSource.MediaPeriodId;
import androidx.media3.exoplayer.source.MediaSourceEventListener;
-import androidx.media3.exoplayer.source.MediaSourceFactory;
import androidx.media3.exoplayer.upstream.Allocator;
import java.io.IOException;
import java.lang.annotation.Documented;
@@ -130,7 +129,7 @@ public final class AdsMediaSource extends CompositeMediaSource
If specifying a {@link MediaSourceFactory} using {@link - * Transformer.Builder#setMediaSourceFactory(MediaSourceFactory)}, make sure that {@link + *
If specifying a {@link MediaSource.Factory} using {@link + * Transformer.Builder#setMediaSourceFactory(MediaSource.Factory)}, make sure that {@link * Mp4Extractor#FLAG_READ_SEF_DATA} is set on the {@link Mp4Extractor} used. Otherwise, the slow * motion metadata will be ignored and the input won't be flattened. * diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/Transformer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/Transformer.java index 421132dee3..a95ea82720 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/Transformer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/Transformer.java @@ -53,7 +53,6 @@ import androidx.media3.exoplayer.audio.AudioRendererEventListener; import androidx.media3.exoplayer.metadata.MetadataOutput; import androidx.media3.exoplayer.source.DefaultMediaSourceFactory; import androidx.media3.exoplayer.source.MediaSource; -import androidx.media3.exoplayer.source.MediaSourceFactory; import androidx.media3.exoplayer.text.TextOutput; import androidx.media3.exoplayer.trackselection.DefaultTrackSelector; import androidx.media3.exoplayer.video.VideoRendererEventListener; @@ -95,7 +94,7 @@ public final class Transformer { private @MonotonicNonNull Context context; // Optional fields. - private @MonotonicNonNull MediaSourceFactory mediaSourceFactory; + private MediaSource.@MonotonicNonNull Factory mediaSourceFactory; private Muxer.Factory muxerFactory; private boolean removeAudio; private boolean removeVideo; @@ -173,14 +172,14 @@ public final class Transformer { } /** - * Sets the {@link MediaSourceFactory} to be used to retrieve the inputs to transform. The + * Sets the {@link MediaSource.Factory} to be used to retrieve the inputs to transform. The * default value is a {@link DefaultMediaSourceFactory} built with the context provided in * {@link #Builder(Context) the constructor}. * - * @param mediaSourceFactory A {@link MediaSourceFactory}. + * @param mediaSourceFactory A {@link MediaSource.Factory}. * @return This builder. */ - public Builder setMediaSourceFactory(MediaSourceFactory mediaSourceFactory) { + public Builder setMediaSourceFactory(MediaSource.Factory mediaSourceFactory) { this.mediaSourceFactory = mediaSourceFactory; return this; } @@ -473,7 +472,7 @@ public final class Transformer { public static final int PROGRESS_STATE_NO_TRANSFORMATION = 4; private final Context context; - private final MediaSourceFactory mediaSourceFactory; + private final MediaSource.Factory mediaSourceFactory; private final Muxer.Factory muxerFactory; private final boolean removeAudio; private final boolean removeVideo; @@ -492,7 +491,7 @@ public final class Transformer { private Transformer( Context context, - MediaSourceFactory mediaSourceFactory, + MediaSource.Factory mediaSourceFactory, Muxer.Factory muxerFactory, boolean removeAudio, boolean removeVideo,