PlayerManager
public class PlayerManager
The PlayerManager class is responsible for managing the playback of media content, including handling
tracks, ads, and user interface components. It provides a high-level interface for controlling media playback of Vesper platform content
-
The provider that supplies the underlying player instance used for media playback.
Declaration
Swift
public let playerProvider: PlayerProvider -
Provides access to available ad breaks for content, also capable of converting stream time to content time and vice versa
Declaration
Swift
public let adBreaksManager: AdBreaksManager -
Manages the available media tracks (such as audio and subtitles) during playback.
Declaration
Swift
public let tracksManager: TracksManager -
Manages the available playback queue next/previous items
Declaration
Swift
public var queueManager: QueueManager -
Manages default user interface components related to media playback, if default is selected during initialization of PlayerManager.
Declaration
Swift
public let uiManager: UIManager? -
A boolean value that indicates whether the player is muted.
The
isMutedproperty allows you to mute or unmute the player. Setting this property totruemutes the audio, while setting it tofalseunmutes it.Declaration
Swift
public var isMuted: Bool { get set } -
The current stream time in seconds.
The
currentTimeproperty returns the current position of the playback in seconds(includes SSAI ads time if available, use adBreaksManager.timeConverter to exclude ads if needed). If no content is loaded or the current time is unavailable, this property returnsnil.Declaration
Swift
public var currentTime: Double? { get } -
The total duration in seconds
The
durationproperty returns the full length of the content in seconds(includes SSAI ads time if available, use adBreaksManager.timeConverter to exclude ads if needed). If the duration is unavailable (e.g., for live streams or unbuffered content), this property returnsnil.Declaration
Swift
public var duration: Double? { get } -
The seekable range, represented as a start and end time in seconds.
The
seekableRangesproperty provides the start and end points of the portion of the content(includes SSAI ads time if available, use adBreaksManager.timeConverter to exclude ads if needed)Declaration
Swift
public var seekableRanges: (start: Double, end: Double)? { get } -
The current playback rate of the player.
The
playbackRateproperty reflects the speed at which the player is playing the content. A value of 1.0 indicates normal speed, while values greater than 1.0 indicate fast-forward, and values less than 1.0 indicate slow-motion playback.Declaration
Swift
public var playbackRate: Double { get set } -
The current state of the player, represented by a
DorisPlayerStatevalue.The
playerStateproperty provides information about the current state of the player, such as whether it is playing, paused, buffering, failed etc. This state can be used to control the player behavior or update the UI based on the current state.Declaration
Swift
public var playerState: DorisPlayerState { get } -
Loads the specified media source and begins playback.
The
loadmethod initializes the media player with the providedResolvableSourceand starts playback. This method can handle both on-demand and live content.Important
Completion if this method does not indicate that underlying AVPlayer finished loading AVPlayerItem, instead, it indicates that AVPlayerItem was sucessfuly resolved from
ResolvableSource, to track AVPlayerItem loaded rely on PlayerState.loaded event delivered throughDorisPlayerOutputProtocolExample:
playerManager.load(source: myMediaSource) { error in if let error = error { print("Failed to resolve media: \(error)") } }
Declaration
Swift
public func load(source: ResolvableSource, autoPlay: Bool = true, completion: @escaping (Error?) -> Void)Parameters
sourceA
ResolvableSourceinstance representing the media content to be loaded.autoPlaywether to keep player paused or play immediately after load
completionA closure that is called when the PlaybackSource is resolved from API and playback successfully initiated with AVPLayer. If the PlaybackSource resolving fails, the closure is called with an
Error. -
Unloads the currently loaded media, stopping playback, clears analytics services and releasing resources.
Equivalent of AVPlayer.replaceCurrentItem(with: nil)
The
unloadmethod stops the playback of the current media and releases any resources associated with it. This method can be used when the user navigates away from the media or when the app needs to free up memory.Declaration
Swift
public func unload() -
Pauses the playback of the media.
The
pausemethod temporarily halts playback, allowing it to be resumed later from the same position.Declaration
Swift
public func pause() -
Starts or resumes the playback of the media.
The
playmethod begins playing the loaded media. If the media is paused or stopped, this method resumes playback from the current position.Declaration
Swift
public func play() -
Seeks to a specified position in the media content.
The
seekmethod allows you to move the playback position to a specified time or range within the content. This method can be used for fast-forwarding, rewinding, or jumping to a specific timestamp.Example:
playerManager.seek(.position(30)) { isCompleted in if isCompleted { print("Seek completed successfully") } else { print("Seek failed") } }
Declaration
Swift
public func seek(_ type: SeekType, callback: ((_ isCompleted: Bool) -> Void)? = nil)Parameters
typeA
SeekTypevalue that specifies the seek behavior (e.g., to a specific time, relative time, etc.).callbackAn optional closure that is called when the seek operation is complete, with a boolean indicating whether the seek was successful.