Interface MediaSource
-
- All Known Implementing Classes:
AdsMediaSource,BaseMediaSource,ClippingMediaSource,CompositeMediaSource,ConcatenatingMediaSource,ConcatenatingMediaSource2,DashMediaSource,FakeAdaptiveMediaSource,FakeMediaSource,FilteringMediaSource,HlsMediaSource,ImaServerSideAdInsertionMediaSource,LoopingMediaSource,MaskingMediaSource,MergingMediaSource,ProgressiveMediaSource,RtspMediaSource,ServerSideAdInsertionMediaSource,SilenceMediaSource,SingleSampleMediaSource,SsMediaSource,WrappingMediaSource
@Deprecated public interface MediaSource
Deprecated.com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.Defines and provides media to be played by anExoPlayer. A MediaSource has two main responsibilities:- To provide the player with a
Timelinedefining the structure of its media, and to provide a new timeline whenever the structure of the media changes. The MediaSource provides these timelines by callingMediaSource.MediaSourceCaller.onSourceInfoRefreshed(com.google.android.exoplayer2.source.MediaSource, com.google.android.exoplayer2.Timeline)on theMediaSource.MediaSourceCallers passed toprepareSource(MediaSourceCaller, TransferListener, PlayerId). - To provide
MediaPeriodinstances for the periods in its timeline. MediaPeriods are obtained by callingcreatePeriod(MediaPeriodId, Allocator, long), and provide a way for the player to load and read the media.
MediaSourcemethods should not be called from application code. Instead, the playback logic inExoPlayerwill trigger methods at the right time.Instances can be re-used, but only for one
ExoPlayerinstance simultaneously.MediaSource methods will be called on one of two threads, an application thread or a playback thread. Each method is documented with the thread it is called on.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceMediaSource.FactoryDeprecated.Factory for creatingMediaSourcesfromMediaItems.static classMediaSource.MediaPeriodIdDeprecated.Identifier for aMediaPeriod.static interfaceMediaSource.MediaSourceCallerDeprecated.A caller of media sources, which will be notified of source events.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description voidaddDrmEventListener(Handler handler, DrmSessionEventListener eventListener)Deprecated.Adds aDrmSessionEventListenerto the list of listeners which are notified of DRM events for this media source.voidaddEventListener(Handler handler, MediaSourceEventListener eventListener)Deprecated.Adds aMediaSourceEventListenerto the list of listeners which are notified of media source events.MediaPeriodcreatePeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs)Deprecated.Returns a newMediaPeriodidentified byperiodId.voiddisable(MediaSource.MediaSourceCaller caller)Deprecated.Disables the source for the creation ofMediaPeriods.voidenable(MediaSource.MediaSourceCaller caller)Deprecated.Enables the source for the creation ofMediaPeriods.default TimelinegetInitialTimeline()Deprecated.Returns the initial placeholder timeline that is returned immediately when the real timeline is not yet known, or null to let the player create an initial timeline.MediaItemgetMediaItem()Deprecated.Returns theMediaItemwhose media is provided by the source.default booleanisSingleWindow()Deprecated.Returns true if the media source is guaranteed to never have zero or more than one window.voidmaybeThrowSourceInfoRefreshError()Deprecated.Throws any pending error encountered while loading or refreshing source information.default voidprepareSource(MediaSource.MediaSourceCaller caller, TransferListener mediaTransferListener)Deprecated.ImplementprepareSource(MediaSourceCaller, TransferListener, PlayerId)instead.voidprepareSource(MediaSource.MediaSourceCaller caller, TransferListener mediaTransferListener, PlayerId playerId)Deprecated.Registers aMediaSource.MediaSourceCaller.voidreleasePeriod(MediaPeriod mediaPeriod)Deprecated.Releases the period.voidreleaseSource(MediaSource.MediaSourceCaller caller)Deprecated.Unregisters a caller, and disables and releases the source if no longer required.voidremoveDrmEventListener(DrmSessionEventListener eventListener)Deprecated.Removes aDrmSessionEventListenerfrom the list of listeners which are notified of DRM events for this media source.voidremoveEventListener(MediaSourceEventListener eventListener)Deprecated.Removes aMediaSourceEventListenerfrom the list of listeners which are notified of media source events.
-
-
-
Method Detail
-
addEventListener
void addEventListener(Handler handler, MediaSourceEventListener eventListener)
Deprecated.Adds aMediaSourceEventListenerto the list of listeners which are notified of media source events.Should not be called directly from application code.
This method must be called on the playback thread.
- Parameters:
handler- A handler on the which listener events will be posted.eventListener- The listener to be added.
-
removeEventListener
void removeEventListener(MediaSourceEventListener eventListener)
Deprecated.Removes aMediaSourceEventListenerfrom the list of listeners which are notified of media source events.Should not be called directly from application code.
This method must be called on the playback thread.
- Parameters:
eventListener- The listener to be removed.
-
addDrmEventListener
void addDrmEventListener(Handler handler, DrmSessionEventListener eventListener)
Deprecated.Adds aDrmSessionEventListenerto the list of listeners which are notified of DRM events for this media source.Should not be called directly from application code.
This method must be called on the playback thread.
- Parameters:
handler- A handler on the which listener events will be posted.eventListener- The listener to be added.
-
removeDrmEventListener
void removeDrmEventListener(DrmSessionEventListener eventListener)
Deprecated.Removes aDrmSessionEventListenerfrom the list of listeners which are notified of DRM events for this media source.Should not be called directly from application code.
This method must be called on the playback thread.
- Parameters:
eventListener- The listener to be removed.
-
getInitialTimeline
@Nullable default Timeline getInitialTimeline()
Deprecated.Returns the initial placeholder timeline that is returned immediately when the real timeline is not yet known, or null to let the player create an initial timeline.Should not be called directly from application code.
The initial timeline must use the same uids for windows and periods that the real timeline will use. It also must provide windows which are marked as dynamic to indicate that the window is expected to change when the real timeline arrives.
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.
This method must be called on the application thread.
-
isSingleWindow
default boolean isSingleWindow()
Deprecated.Returns true if the media source is guaranteed to never have zero or more than one window.Should not be called directly from application code.
The default implementation returns
true.This method must be called on the application thread.
- Returns:
- true if the source has exactly one window.
-
getMediaItem
MediaItem getMediaItem()
Deprecated.Returns theMediaItemwhose media is provided by the source.Should not be called directly from application code.
This method must be called on the application thread.
-
prepareSource
@Deprecated default void prepareSource(MediaSource.MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener)
Deprecated.ImplementprepareSource(MediaSourceCaller, TransferListener, PlayerId)instead.
-
prepareSource
void prepareSource(MediaSource.MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener, PlayerId playerId)
Deprecated.Registers aMediaSource.MediaSourceCaller. Starts source preparation if needed and enables the source for the creation ofMediaPerods.Should not be called directly from application code.
MediaSource.MediaSourceCaller.onSourceInfoRefreshed(MediaSource, Timeline)will be called once the source has aTimeline.For each call to this method, a call to
releaseSource(MediaSourceCaller)is needed to remove the caller and to release the source if no longer required.This method must be called on the playback thread.
- Parameters:
caller- TheMediaSource.MediaSourceCallerto be registered.mediaTransferListener- The transfer listener which should be informed of any media data transfers. May be null if no listener is available. Note that this listener should be only informed of transfers related to the media loads and not of auxiliary loads for manifests and other data.playerId- ThePlayerIdof the player using this media source.
-
maybeThrowSourceInfoRefreshError
void maybeThrowSourceInfoRefreshError() throws IOExceptionDeprecated.Throws any pending error encountered while loading or refreshing source information.Should not be called directly from application code.
This method must be called on the playback thread and only after
prepareSource(MediaSourceCaller, TransferListener, PlayerId).- Throws:
IOException
-
enable
void enable(MediaSource.MediaSourceCaller caller)
Deprecated.Enables the source for the creation ofMediaPeriods.Should not be called directly from application code.
This method must be called on the playback thread and only after
prepareSource(MediaSourceCaller, TransferListener, PlayerId).- Parameters:
caller- TheMediaSource.MediaSourceCallerenabling the source.
-
createPeriod
MediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs)
Deprecated.Returns a newMediaPeriodidentified byperiodId.Should not be called directly from application code.
This method must be called on the playback thread and only if the source is enabled.
- Parameters:
id- The identifier of the period.allocator- AnAllocatorfrom which to obtain media buffer allocations.startPositionUs- The expected start position, in microseconds.- Returns:
- A new
MediaPeriod.
-
releasePeriod
void releasePeriod(MediaPeriod mediaPeriod)
Deprecated.Releases the period.Should not be called directly from application code.
This method must be called on the playback thread.
- Parameters:
mediaPeriod- The period to release.
-
disable
void disable(MediaSource.MediaSourceCaller caller)
Deprecated.Disables the source for the creation ofMediaPeriods. The implementation should not hold onto limited resources used for the creation of media periods.Should not be called directly from application code.
This method must be called on the playback thread and only after all
MediaPeriodspreviously created bycreatePeriod(MediaPeriodId, Allocator, long)have been released byreleasePeriod(MediaPeriod).- Parameters:
caller- TheMediaSource.MediaSourceCallerdisabling the source.
-
releaseSource
void releaseSource(MediaSource.MediaSourceCaller caller)
Deprecated.Unregisters a caller, and disables and releases the source if no longer required.Should not be called directly from application code.
This method must be called on the playback thread and only if all created
MediaPeriodshave been released byreleasePeriod(MediaPeriod).- Parameters:
caller- TheMediaSource.MediaSourceCallerto be unregistered.
-
-