# Playback Engine
The Playback Engine is the component ByteArk Player SDK uses to play video/audio. The default playback engine is AVPlayer from the iOS SDK.
ByteArk Player SDK lets you build your own playback engine — for example, a WebRTC engine, or an engine that uses VLCKit (opens new window).
To do that, the SDK provides:
- The
ByteArkPlayerPlaybackEngineprotocol that your engine must implement. ByteArkPlayer uses its variables and methods to get information and control the content. - The
ByteArkPlayerPlaybackEngineNotificationenum that your engine uses to send events to the ByteArkPlayer instance, UI components, and other plugins.
ByteArkPlayerPlaybackEngine protocol
@objc public protocol ByteArkPlayerPlaybackEngine: AnyObject {
/// Is the engine ready to play content
var isReady: Bool { get }
/// Is currently playing
var isPlaying: Bool { get }
/// Is currently seeking
var isSeeking: Bool { get }
/// Is currently buffering
var isBuffering: Bool { get }
/// Is muted
var isMuted: Bool { get }
/// Content is ended
var isEnded: Bool { get }
/// Is in Picture-in-Picture mode
var isInPictureInPicture: Bool { get }
/// Supports Picture-in-Picture
var isSupportedPictureInPicture: Bool { get }
/// Picture-in-Picture is enabled
var isEnabledPictureInPicture: Bool { get }
/// Is in fullscreen mode
var isFullscreen: Bool { get }
/// Current playback time
var time: TimeInterval { get }
/// Duration of the current item
var duration: TimeInterval { get }
/// Active audio track
var audioTrack: ByteArkPlayerMediaTrack? { get }
/// All audio tracks for the current item
var audioTracks: [ByteArkPlayerMediaTrack] { get }
/// Active subtitle track
var subtitleTrack: ByteArkPlayerMediaTrack? { get }
/// All subtitle tracks for the current item
var subtitleTracks: [ByteArkPlayerMediaTrack] { get }
/// Active resolution
var resolution: ByteArkPlayerMediaResolution? { get }
/// All resolutions for the current item
var resolutions: [ByteArkPlayerMediaResolution] { get }
/// Current playback speed
var playbackSpeed: Float { get }
/// Current playback volume
var playbackVolume: Float { get }
/// The view that renders the content (e.g., a UIView subclass containing AVPlayerLayer)
@objc func getRenderingView() -> UIView
/// Play content
@objc func play()
/// Pause content
@objc func pause()
/// Seek to a given time
@objc func seek(to time: TimeInterval, completionHandler: @escaping (Bool) -> Void)
/// Mute / unmute
@objc func muted(_ muted: Bool)
/// Set the current playback item
@objc func setPlaybackItem(_ item: ByteArkPlayerItem?)
/// Enter Picture-in-Picture
@objc func enterPictureInPictureMode()
/// Exit Picture-in-Picture
@objc func exitPictureInPictureMode()
/// Enable Picture-in-Picture (when supported)
@objc func enablePictureInPictureMode()
/// Disable Picture-in-Picture
@objc func disablePictureInPictureMode()
/// Enter fullscreen
@objc func enterFullscreenMode()
/// Exit fullscreen
@objc func exitFullscreenMode()
/// Set audio track
@objc func setAudioTrack(_ audioTrack: ByteArkPlayerMediaTrack)
/// Set subtitle track
@objc func setSubtitleTrack(_ subtitleTrack: ByteArkPlayerMediaTrack?)
/// Set resolution
@objc func setResolution(_ resolution: ByteArkPlayerMediaResolution)
/// Set playback speed
@objc func setPlaybackSpeed(_ speed: Float)
/// Set playback volume
@objc func setPlaybackVolume(_ volume: Float)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
ByteArkPlayerPlaybackEngineNotification
public enum ByteArkPlayerPlaybackEngineNotification : String {
case ready
case loadingMetadata
case loadedMetadata
case firstPlay
case play
case pause
case seeking
case seeked
case ended
case stalled
case buffering
case buffered
case timeupdate
case error
case playbackItemReady
case enterPictureInPictureMode
case exitPictureInPictureMode
case enablePictureInPictureMode
case disablePictureInPictureMode
case muted
case unmuted
case enterFullscreenMode
case exitFullscreenMode
case playbackSpeedChanged
case playbackVolumeChanged
case audioTrackChanged
case subtitleTrackChanged
case resolutionChanged
case playlistItemChanged
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
To add your playback engine to ByteArkPlayer, use the .playbackEngine() method on ByteArkPlayerConfigBuilder:
do {
let customPlaybackEngine = CustomPlaybackEngine()
let config = try ByteArkPlayerConfigBuilder()
.item(item)
.autoplay(true)
.playbackEngine(customPlaybackEngine)
.build()
player.configure(with: config)
} catch {
print(error.localizedDescription)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13