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
Timeline
defining 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.MediaSourceCaller
s passed toprepareSource(MediaSourceCaller, TransferListener, PlayerId)
. - To provide
MediaPeriod
instances 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.
MediaSource
methods should not be called from application code. Instead, the playback logic inExoPlayer
will trigger methods at the right time.Instances can be re-used, but only for one
ExoPlayer
instance 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 interface
MediaSource.Factory
Deprecated.Factory for creatingMediaSources
fromMediaItems
.static class
MediaSource.MediaPeriodId
Deprecated.Identifier for aMediaPeriod
.static interface
MediaSource.MediaSourceCaller
Deprecated.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 void
addDrmEventListener(Handler handler, DrmSessionEventListener eventListener)
Deprecated.Adds aDrmSessionEventListener
to the list of listeners which are notified of DRM events for this media source.void
addEventListener(Handler handler, MediaSourceEventListener eventListener)
Deprecated.Adds aMediaSourceEventListener
to the list of listeners which are notified of media source events.MediaPeriod
createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs)
Deprecated.Returns a newMediaPeriod
identified byperiodId
.void
disable(MediaSource.MediaSourceCaller caller)
Deprecated.Disables the source for the creation ofMediaPeriods
.void
enable(MediaSource.MediaSourceCaller caller)
Deprecated.Enables the source for the creation ofMediaPeriods
.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.MediaItem
getMediaItem()
Deprecated.Returns theMediaItem
whose media is provided by the source.default boolean
isSingleWindow()
Deprecated.Returns true if the media source is guaranteed to never have zero or more than one window.void
maybeThrowSourceInfoRefreshError()
Deprecated.Throws any pending error encountered while loading or refreshing source information.default void
prepareSource(MediaSource.MediaSourceCaller caller, TransferListener mediaTransferListener)
Deprecated.ImplementprepareSource(MediaSourceCaller, TransferListener, PlayerId)
instead.void
prepareSource(MediaSource.MediaSourceCaller caller, TransferListener mediaTransferListener, PlayerId playerId)
Deprecated.Registers aMediaSource.MediaSourceCaller
.void
releasePeriod(MediaPeriod mediaPeriod)
Deprecated.Releases the period.void
releaseSource(MediaSource.MediaSourceCaller caller)
Deprecated.Unregisters a caller, and disables and releases the source if no longer required.void
removeDrmEventListener(DrmSessionEventListener eventListener)
Deprecated.Removes aDrmSessionEventListener
from the list of listeners which are notified of DRM events for this media source.void
removeEventListener(MediaSourceEventListener eventListener)
Deprecated.Removes aMediaSourceEventListener
from the list of listeners which are notified of media source events.
-
-
-
Method Detail
-
addEventListener
void addEventListener(Handler handler, MediaSourceEventListener eventListener)
Deprecated.Adds aMediaSourceEventListener
to 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 aMediaSourceEventListener
from 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 aDrmSessionEventListener
to 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 aDrmSessionEventListener
from 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 theMediaItem
whose 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.MediaSourceCaller
to 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
- ThePlayerId
of the player using this media source.
-
maybeThrowSourceInfoRefreshError
void maybeThrowSourceInfoRefreshError() throws IOException
Deprecated.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.MediaSourceCaller
enabling the source.
-
createPeriod
MediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs)
Deprecated.Returns a newMediaPeriod
identified 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
- AnAllocator
from 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
MediaPeriods
previously created bycreatePeriod(MediaPeriodId, Allocator, long)
have been released byreleasePeriod(MediaPeriod)
.- Parameters:
caller
- TheMediaSource.MediaSourceCaller
disabling 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
MediaPeriods
have been released byreleasePeriod(MediaPeriod)
.- Parameters:
caller
- TheMediaSource.MediaSourceCaller
to be unregistered.
-
-