public protocol PlayerAPI : ViewBasedAPI
Control and manage the video player instance.
public protocol PlayerAPI : ViewBasedAPI
Control and manage the video player instance.
Returns the engine used by this player instance.
Swift
var engine: PlayerEngine { get }
Returns current stream playback state.
Swift
var playbackState: PlaybackState? { get }
Returns stream current position.
Swift
var position: Double? { get }
Triggered when playback state has changed.
Swift
var onState: ((_ previous: PlaybackState, _ state: PlaybackState) -> Void)? { get set }
Set callback for current time changes at a desired rate.
Rate is specified in seconds with milliseconds precision. Min: 0.1
.
Swift
func onCurrentTime(rate: Double, onChange: @escaping ((Double) -> Void))
Set callback for playback stats.
Swift
var onStats: ((Stats) -> Void)? { get set }
Get playback stats. If stats are not available the returned value is nil
Swift
func getStats() -> Stats?
Returns the live start time in seconds since the epoch or nil
if unknown or not
applicable.
Remark
Available when player is in statePlaybackState.ready
.
Swift
func getLiveStartTime() -> Double?
Triggered on track model change.
Swift
var onTrackModel: (() -> Void)? { get set }
Returns the current track model.
Swift
var tracks: Tracks { get }
Load new player configuration.
Swift
func load(config: PlayerConfiguration)
config
|
Player configuration. |
Return the currently selected video track or null if no track is active and selected.
Swift
func getVideoTrack() -> VideoTrack?
Return the rendition that is currently selected by ABR or manually.
Remark
This may returnnil
for streams played by PlayerEngine.apple
due to a
limitation of the underlying player.
Swift
func getSelectedVideoRendition() -> VideoRendition?
Return the currently rendered rendition.
Swift
func getRenderedVideoRendition() -> VideoRendition?
Return the currently selected audio track or null if no track is active and selected.
Swift
func getAudioTrack() -> AudioTrack?
Return the currently selected audio rendition or null if no audio track is active and selected.
Remark
This may return nil for streams played byPlayerEngine.apple
due to a limitation
of the underlying player.
Swift
func getSelectedAudioRendition() -> AudioRendition?
Return the currently rendered audio rendition or null if no audio track is active and selected.
Swift
func getRenderedAudioRendition() -> AudioRendition?
Return the currently selected text track or null if no track is active and selected.
Swift
func getTextTrack() -> TextTrack?
Selects the given rendition and disables ABR mode. If nil
is passed, ABR becomes enabled.
Remark
Not availble for PlayerEngine.apple
.
Swift
func setVideoRendition(_ rendition: VideoRendition?)
rendition
|
Video rendition. |
Selects the given video track.
Swift
func setVideoTrack(_ track: VideoTrack)
track
|
Video track. |
Selects the given audio track.
Swift
func setAudioTrack(_ track: AudioTrack)
track
|
Audio track. |
Selects the given subtitles track. Passing nil
disables subtitles.
Swift
func setTextTrack(_ track: TextTrack?)
Returns true
is manual video rendition is enabled, false
if ABR is enabled.
Swift
var isAdaptationModeManual: Bool { get }
The percentage of buffered data relative to the total duration. Represents a value in the range [0, 100].
Swift
var bufferedPercentage: Float? { get }
Initalise the AVPictureInPictureController
and returns a reference of it.
Remark
Works only with PlayerEngine.apple
. From our tests, the PiP playback becomes
available on most devices when the player moves to PlaybackState.playing
.
Swift
@available(tvOS 14.0, *)
func getPictureInPictureController() -> AVPictureInPictureController?
An initiliazed AVPictureInPictureController
object.
Indicates whether the player should continue the playback in the background. The default
value is false
.
Besides setting this flag to true
please add the UIBackgroundModes key in your app’s
Info.plist
file. Its value is an array that contains one or more strings that identify
which background tasks your application supports. Specify the string value audio
.
Remark
Works only for audio-only streams. Must be called before state.open
.
Swift
var continueAudioPlaybackInBackground: Bool { get set }
A value of 1.0 (default) plays the current item at its natural rate. Setting to values lower than 1 slow down the playback; values higher than 1 speed it up.
Remark
Content played atplaybackRate
lower than 0.0
or higher than 2.0
will have
audio muted.
Remark
Expects frame drops for high values.Remark
Negative rates only work withPlayerEngine.apple
. The player will use the
I-Frame playlist if present otherwise it would try to play it anyways (which usually result
in a sketcky playback). In both cases audio is muted.
Swift
var playbackRate: Double { get set }
The playback volume of the player instance, ranging from 0.0 through 1.0 on a linear scale. A value of 0.0 indicates silence; a value of 1.0 (the default) indicates full volume for the audio queue instance.
Remark
This value does not impact the device overall volume. Setting it at 1.0 (default) means: “play at the device current max volume”.Remark
Must be called after the player transitions toPlaybackState.ready
.
Remark
When used withPlayerEngine.apple
, please consider this note from Apple: “Do not
use this property to implement a volume slider for media playback. For that purpose, use
MPVolumeView, which is customizable in appearance and provides standard media playback
behaviors that users expect.
This property is most useful on iOS to control the volume of the AVPlayer relative to other audio output, not for volume control by end users.
Swift
var playbackVolume: Double { get set }
Starts loading the content. The player will transition to PlaybackState.opening
until it
has enough meta-data loaded to build up a track model and then transition to
PlaybackState.ready
.
Swift
func open(autoplay: Bool)
autoplay
|
Whether the content shall start play automatically after the player
reaches the |
Start playback. The player will transition into PlaybackState.play
and into
PlaybackState.playing
once the frames appear on screen.
Calling this method when player is PlaybackState.idle
is equivalent to
open(autoplay:true)
.
Swift
func play()
Pause playback. The player will transition into PlaybackState.pausing
and then into
PlaybackState.paused
once the frames pause on screen.
Swift
func pause()
Stop playback. The player will transition into PlaybackState.stopping
state and then into
PlaybackState.ended
once the playback stops.
Swift
func stop()
Starts loading the content. The player will transition to PlaybackState.seeking
. The
player can either reach the new position in its buffer and will transition back to
PlaybackState.play
or PlaybackState.pausing
depending on where it came from or it will
first transition into PlaybackState.buffering
if the requested position is not found in
the current buffer.
Swift
func seek(_ time: CMTime)
time
|
Seeking position. |
A collection of time ranges that the player can seek to. The ranges provided might be discontinous.
Swift
var seekableTimeRanges: [CMTimeRange] { get }
Minimum buffer required until playback begins (default: 6 seconds
)
Remark
remark Works only for DASH and SmoothStreaming streamsSwift
var minPrebufferTime: Double { get set }
Maximum buffer size allowed (default: 60 seconds
). When filled to maximum, new downloads
will be paused
Remark
Works only for content played with player engine.castlabs
Swift
var maxPrebufferTime: Double { get set }
Minimum buffer required after buffer underruns (default: 12 seconds
)
Works only for content played with player engine .castlabs
Swift
var minRebufferTime: Double { get set }
Return true
for live streams, false
otherwise.
Swift
var isLive: Bool { get }
Initial live latency target - how many seconds before the live edge the playback should start (default: 10 seconds).
Swift
var liveEdgeDelay: Double { get set }
Enable to make player attempt to move as closer to live edge as possible.
Default is .disabled
Swift
var chaseLiveEdge: ChaseLiveEdge { get set }
Maximum time to stay behind live edge, seconds
Default is 10.0
Swift
var chaseLiveEdgeCatchupThreshold: Double { get set }
Nominal time to stay behind live edge, seconds
Default is 5.0
Swift
var chaseLiveEdgeCutoffThreshold: Double { get set }
Duration of HLS segment in seconds
Used when live edge chasing is set to .skipFrames
.
Default is 10.0
Swift
var chaseLiveEdgeHLSSegmentDuration: Double { get set }
Playback speed increase
Used when live edge chasing is set to .speedupPlayback
Default is 1.1
Swift
var chaseLiveEdgeSpeedupRatio: Double { get set }
Get stream duration in seconds.
Swift
var duration: Double { get }
Returns the drm component in use by the player (if any).
Swift
var drm: DrmAPI? { get }
Video gravity determines how the video content is scaled or stretched within the player bounds.
Remark
Default value isAVLayerVideoGravityResizeAspect
.
The player layer supports the following video gravity values:
AVLayerVideoGravityResizeAspect
: Player should preserve the video’s aspect ratio and
fit the video within the bounds.AVLayerVideoGravityResizeAspectFill
: Player should preserve the video’s aspect ratio
and fill the bounds.AVLayerVideoGravityResize
: Video should be stretched to fill the bounds.Swift
var videoGravity: AVLayerVideoGravity { get set }
Returns underlining AVPLayer.
Remark
Works only withPlayerEngine.apple
.
Remark
Should be used for debugging purpose mainly. Using this object to modify the playback may lead to unexpected and conflicting behaviour with our API.Swift
var avPlayerInstance: AVPlayer? { get }
Fatal error that caused the player to enter .error state
Swift
var error: PRESTOError? { get }
Request modifiers used for this player instance
Swift
var requestModifiers: [any RequestModifierProtocol]? { get set }
Response modifiers used for this player instance
Swift
var responseModifiers: [any ResponseModifierProtocol]? { get set }