Source
@objc(BMPSource)
public protocol Source : SourceEventHandler
Represents audio and video content that can be loaded into a Player
. A Source instance can be created via the
SourceFactory.create
function and will idle until it is loaded into a player. After loading the source
into a player, isAttachedToPlayer
is true
and the same source can not be loaded into a different player until
unloaded.
Multiple sources can be loaded into a player as part of a PlaylistConfig
, where the first source in the playlist
immediately becomes active. When the player transitions to another source in the playlist, that source
becomes active. More information on how to manage multiple sources can be found on the PlaylistApi
.
The source starts out LoadingState.unloaded
, transitions to LoadingState.loading
once the source starts
loading and finally transitions to LoadingState.loaded
when it finished loading. When unloaded from a player, the
source reverts to being LoadingState.unloaded
and detached. After this, the source can be loaded again
into a (different) player.
The source emits events while it is attached to a player. See SourceEventHandler
on how to subscribe to events.
The source only emits events of type SourceEvent
, and events that are emitted while the source is active
are also emitted through the player it is attached to.
Current event-related limitations
Only a few events are currently emitted from the source. This is a temporary limitation until
all source events are emitted correctly from the source.
See SourceListener
for more information about events emitted from the source.
-
The SourceConfig that was used to configure the source.
Declaration
Swift
var sourceConfig: SourceConfig { get }
-
Whether the source is currently attached to a player instance (i.e if the source was loaded into a player or it is part of a
PlaylistConfig
that was loaded into a player).Declaration
Swift
var isAttachedToPlayer: Bool { get }
-
Whether the source is currently active in a
Player
(i.e. playing back or paused). Only one source can be active in the same player instance at any time.Declaration
Swift
var isActive: Bool { get }
-
The duration of the source in seconds if it’s a VoD or
Double.infinity
if it’s a live stream. Default value is0
if the duration is not available or not known.Declaration
Swift
var duration: TimeInterval { get }
-
The current
LoadingState
of the source.Declaration
Swift
var loadingState: LoadingState { get }
-
Metadata for the currently loaded source. All existing metadata will be completely replaced by the provided metadata when the setter is called. For example, if sourceMetadata is an empty object, all existing source metadata will be deleted. Setting new metadata results in a
SourceMetadataChanged
event to be emitted. The initial value can be set viaSourceConfig.metadata
.Declaration
Swift
var metadata: [String : AnyObject]? { get set }
-
The
_SourceModulesApi
for interactions regarding modules.Declaration
Swift
var _modules: _SourceModulesApi { get }
-
The
SourceEventsApi
for interactions regarding event publishers. This API is only available for usage from Swift.Declaration
Swift
var events: SourceEventsApi { get }
-
The
SourceDrmApi
for interactions regarding DRM specific APIs.Declaration
Swift
var drm: SourceDrmApi { get }
-
The
SourceLatencyApi
for interactions regarding latency specific APIs for live-streams.Declaration
Swift
var latency: SourceLatencyApi { get }
-
Returns the thumbnail image for a certain time. Requires a configured
ThumbnailTrack
in the correspondingSourceConfig
.Note
This function returnsnil
- If the thumbnails were not loaded yet
- If there are no
ThumbnailTrack
provided in the correspondingSourceConfig
If there is no thumbnail available at the provided time
Declaration
Swift
func thumbnail(forTime time: TimeInterval) -> Thumbnail?
Parameters
time
The time for which the thumbnail should be returned.
Return Value
An instance of
Thumbnail
for the given time, ornil
. -
A list of
TimelineMarker
. Currently, the only type of supported marker isInterstitialMarker
. See documentation ofInterstitialMarker
for more information.When a
TimelineMarker
is entered during playback, aTimelineMarkerEnterEvent
is emitted. When aTimelineMarker
is exited during playback, aTimelineMarkerExitEvent
is emitted.The initial value can be set via
SourceConfig.markers
.Declaration
Swift
@available(tvOS 14.0, *) @available(iOS, unavailable) var markers: [TimelineMarker] { get set }
-
analytics
Extension methodAllows access to the Analytics APIs
Returns
nil
if Analytics is not enabled for theSource
Declaration
Swift
var analytics: SourceAnalyticsApi? { get }