# Playback Engine
Playback Engine คือ core ของ ByteArk Player SDK for iOS ซึ่งโดยปกติแล้วจะใช้ AVPlayer ซึ่งเป็น default player บนระบบ iOS ในการเล่นวิดีโอ
ByteArk Player SDK for iOS อนุญาตให้คุณสร้าง Playback Engine สำหรับการเล่นวิดีโอของคุณเอง เช่น Playback Engine ที่สามารถเล่นวิดีโอในรูปแบบ WebRTC live stream หรือ Playback Engine เล่นที่ใช้ VLCKit (opens new window) ในการเล่นวิดีโอ เป็นต้น
ในการสร้าง Playback Engine นั้น ByteArk Player SDK for iOS ได้จัดเตรียมสิ่งต่อไปนี้:
ByteArkPlayerPlaybackEngine
protocol ที่ Playback Engine ของคุณต้องทำการ implement โดย ByteArkPlayer instance จะใช้ variables, methods จาก protocolByteArkPlayerPlaybackEngine
ในการดึงข้อมูลและควบคุมการเล่นวิดีโอByteArkPlayerPlaybackEngineNotification
enum ที่ Playback Engine ของคุณต้องใช้ในการส่งการแจ้งเตือนเหตุการณ์ (event) เพื่อสื่อสารกับ ByteArkPlayer instance, UI components และปลั๊กอินอื่น ๆ
ByteArkPlayerPlaybackEngine Protocol
/// A protocol that playback engine class must be implemented to create custom playback engine
@objc public protocol ByteArkPlayerPlaybackEngine: AnyObject {
/// Check if the playback engine is in ready to play content
var isReady: Bool { get }
/// Check if the playback engine is in playing state
var isPlaying: Bool { get }
/// Check if the playback engine is in seeking state
var isSeeking: Bool { get }
/// Check if the playback engine is in buffering state
var isBuffering: Bool { get }
/// Check if the playback engine is muted
var isMuted: Bool { get }
/// Check if content is ended
var isEnded: Bool { get }
/// Check if the playback engine is in Picture-in-Picture mode
var isInPictureInPicture: Bool { get }
/// Check if the playback engine is supported Picture-in-Picture mode
var isSupportedPictureInPicture: Bool { get }
/// Check if Picture-in-Picture mode is enabled
var isEnabledPictureInPicture: Bool { get }
/// Check if the playback engine is in fullscreen mode
var isFullscreen: Bool { get }
/// Get the current time of the current item.
var time: TimeInterval { get }
/// Get the duration of the current item
var duration: TimeInterval { get }
/// Get the current actived audio track
var audioTrack: ByteArkPlayerMediaTrack? { get }
/// Return an array of the audio tracks of the current playback item
var audioTracks: [ByteArkPlayerMediaTrack] { get }
/// Get the current actived subtitle track
var subtitleTrack: ByteArkPlayerMediaTrack? { get }
/// Return an array of the subtitle tracks of the current playback item
var subtitleTracks: [ByteArkPlayerMediaTrack] { get }
/// Get the current activated resolution
var resolution: ByteArkPlayerMediaResolution? { get }
/// Return an array of the resolution of the current playback item
var resolutions: [ByteArkPlayerMediaResolution] { get }
/// Get the current playback speed
var playbackSpeed: Float { get }
/// Get the current playback volume
var playbackVolume: Float { get }
/// Provide view to display content e.g. UIView subclass that contain AVPlayerLayer
@objc func getRenderingView() -> UIView
/// Tell playback engine to play content
@objc func play()
/// Tell playback engine to pause content
@objc func pause()
/// Tell playback engine to seeks to the given time in seconds
///
/// - Parameters:
/// - time: A time to which to seek in seconds
/// - completionHandler: The block to invoke when the seek operation has either been completed or been interrupted
@objc func seek(to time: TimeInterval, completionHandler: @escaping (Bool) -> Void)
/// Tell playback engine to mute or unmute content volume
///
/// - Parameters:
/// - muted: Boolean to set mute or unmute volume
@objc func muted(_ muted: Bool)
/// Set playback item to playback engine
@objc func setPlaybackItem(_ item: ByteArkPlayerItem?)
/// Enter Picture-in-Picture mode
@objc func enterPictureInPictureMode()
/// Exit Picture-in-Picture mode
@objc func exitPictureInPictureMode()
/// Enable Picture-in-Picture mode if playback engine is supported
@objc func enablePictureInPictureMode()
/// Disable Picture-in-Picture mode
@objc func disablePictureInPictureMode()
/// Enter fullscreen mode
@objc func enterFullscreenMode()
/// Exit fullscreen mode
@objc func exitFullscreenMode()
/// Set audio track to playback engine
/// ///
/// - Parameters:
/// - audioTrack: A ByteArkPlayerMediaTrack object
@objc func setAudioTrack(_ audioTrack: ByteArkPlayerMediaTrack)
/// Set subtitle track to playback engine
///
/// - Parameters:
/// - subtitleTrack: A ByteArkPlayerMediaTrack object or nil
@objc func setSubtitleTrack(_ subtitleTrack: ByteArkPlayerMediaTrack?)
/// Set resolution to playback engine
///
/// - Parameters:
/// - resolution: A ByteArkPlayerMediaResolution object
@objc func setResolution(_ resolution: ByteArkPlayerMediaResolution)
/// Set playback speed to playback engine
///
/// - Parameters:
/// - speed: A playback speed that want to change
@objc func setPlaybackSpeed(_ speed: Float)
/// Set volume to playback engine
///
/// - Parameters:
/// - volume: A playback volume that want to change
@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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
32
33
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
ในการเพิ่ม Playback Engine ของคุณเข้าไปใน ByteArkPlayer ทำได้โดยใช้ method .playbackEngine()
ใน 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