mirror of
https://github.com/videojs/video.js.git
synced 2026-11-20 06:29:27 +01:00
91 lines
3.0 KiB
Swift
91 lines
3.0 KiB
Swift
import Foundation
|
|
|
|
/// One player's state as an `HTMLMediaElement` would report it, property for
|
|
/// property. Immutable: `VideoJSPlayerEngine` changes it by replacing it with an
|
|
/// edited `copy(…)`, so a reader never sees half an update. `initial` holds a
|
|
/// media element's initial values, which is also what a reset restores.
|
|
///
|
|
/// A class rather than a struct so the Objective-C++ module can read it.
|
|
@objc(VideoJSPlayerState)
|
|
public final class VideoJSPlayerState: NSObject {
|
|
@objc public static let initial = VideoJSPlayerState()
|
|
|
|
/// Seconds.
|
|
@objc public let currentTime: Double
|
|
/// Seconds; NaN until known, infinite for live.
|
|
@objc public let duration: Double
|
|
/// `{ start, end }` in seconds, ascending.
|
|
@objc public let buffered: [[String: Double]]
|
|
@objc public let seekable: [[String: Double]]
|
|
/// `{ code, message }`, where `code` is a `MediaError` code.
|
|
@objc public let error: [String: Any]?
|
|
@objc public let paused: Bool
|
|
@objc public let ended: Bool
|
|
@objc public let seeking: Bool
|
|
@objc public let currentSrc: String
|
|
@objc public let readyState: Int
|
|
@objc public let playbackRate: Double
|
|
@objc public let contentData: [String: String]
|
|
|
|
init(
|
|
currentTime: Double = 0,
|
|
duration: Double = .nan,
|
|
buffered: [[String: Double]] = [],
|
|
seekable: [[String: Double]] = [],
|
|
error: [String: Any]? = nil,
|
|
paused: Bool = true,
|
|
ended: Bool = false,
|
|
seeking: Bool = false,
|
|
currentSrc: String = "",
|
|
readyState: Int = 0,
|
|
playbackRate: Double = 1,
|
|
contentData: [String: String] = [:]
|
|
) {
|
|
self.currentTime = currentTime
|
|
self.duration = duration
|
|
self.buffered = buffered
|
|
self.seekable = seekable
|
|
self.error = error
|
|
self.paused = paused
|
|
self.ended = ended
|
|
self.seeking = seeking
|
|
self.currentSrc = currentSrc
|
|
self.readyState = readyState
|
|
self.playbackRate = playbackRate
|
|
self.contentData = contentData
|
|
}
|
|
|
|
/// This snapshot with the given values replaced; anything left out keeps
|
|
/// this snapshot's value. `error` is optional itself, so `.some(nil)` clears
|
|
/// it.
|
|
func copy(
|
|
currentTime: Double? = nil,
|
|
duration: Double? = nil,
|
|
buffered: [[String: Double]]? = nil,
|
|
seekable: [[String: Double]]? = nil,
|
|
error: [String: Any]?? = nil,
|
|
paused: Bool? = nil,
|
|
ended: Bool? = nil,
|
|
seeking: Bool? = nil,
|
|
currentSrc: String? = nil,
|
|
readyState: Int? = nil,
|
|
playbackRate: Double? = nil,
|
|
contentData: [String: String]? = nil
|
|
) -> VideoJSPlayerState {
|
|
VideoJSPlayerState(
|
|
currentTime: currentTime ?? self.currentTime,
|
|
duration: duration ?? self.duration,
|
|
buffered: buffered ?? self.buffered,
|
|
seekable: seekable ?? self.seekable,
|
|
error: error ?? self.error,
|
|
paused: paused ?? self.paused,
|
|
ended: ended ?? self.ended,
|
|
seeking: seeking ?? self.seeking,
|
|
currentSrc: currentSrc ?? self.currentSrc,
|
|
readyState: readyState ?? self.readyState,
|
|
playbackRate: playbackRate ?? self.playbackRate,
|
|
contentData: contentData ?? self.contentData
|
|
)
|
|
}
|
|
}
|