react-native-theoplayer 11.4.0 → 11.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -1
- package/android/src/main/java/com/theoplayer/PlayerEventEmitter.kt +12 -0
- package/ios/RCTBridgeModule+ViewHelpers.swift +59 -0
- package/ios/THEOplayerRCTBridge.m +1 -0
- package/ios/THEOplayerRCTMainEventHandler.swift +1 -0
- package/ios/THEOplayerRCTPlayerAPI.swift +194 -254
- package/ios/THEOplayerRCTTrackMetadataAggregator.swift +2 -2
- package/ios/THEOplayerRCTTypeUtils.swift +16 -0
- package/ios/THEOplayerRCTView.swift +7 -1
- package/ios/ads/THEOplayerRCTAdsAPI+DAI.swift +22 -21
- package/ios/ads/THEOplayerRCTAdsAPI+Omid.swift +4 -9
- package/ios/ads/THEOplayerRCTAdsAPI.swift +39 -50
- package/ios/backgroundAudio/THEOplayerRCTBackgroundAudioManager.swift +1 -1
- package/ios/backgroundAudio/THEOplayerRCTNowPlayingManager.swift +96 -45
- package/ios/cache/THEOplayerRCTCacheAPI.swift +23 -11
- package/ios/casting/THEOplayerRCTCastAPI+Airplay.swift +20 -22
- package/ios/casting/THEOplayerRCTCastAPI+Chromecast.swift +28 -34
- package/ios/casting/THEOplayerRCTCastAPI.swift +5 -8
- package/ios/eventBroadcasting/THEOplayerRCTEventBroadcastAPI.swift +2 -4
- package/ios/theoAds/THEOplayerRCTTHEOAdsAPI.swift +16 -18
- package/ios/theolive/THEOplayerRCTTHEOliveAPI.swift +14 -14
- package/lib/commonjs/api/error/ContentProtectionError.js +2 -0
- package/lib/commonjs/api/error/ContentProtectionError.js.map +1 -0
- package/lib/commonjs/api/error/barrel.js +11 -0
- package/lib/commonjs/api/error/barrel.js.map +1 -1
- package/lib/commonjs/api/event/PlayerEvent.js +8 -0
- package/lib/commonjs/api/event/PlayerEvent.js.map +1 -1
- package/lib/commonjs/api/player/PlayerEventMap.js +1 -0
- package/lib/commonjs/api/player/PlayerEventMap.js.map +1 -1
- package/lib/commonjs/api/track/TextTrack.js +5 -2
- package/lib/commonjs/api/track/TextTrack.js.map +1 -1
- package/lib/commonjs/internal/THEOplayerView.js +4 -0
- package/lib/commonjs/internal/THEOplayerView.js.map +1 -1
- package/lib/commonjs/internal/adapter/WebEventForwarder.js +22 -0
- package/lib/commonjs/internal/adapter/WebEventForwarder.js.map +1 -1
- package/lib/commonjs/internal/adapter/event/PlayerEvents.js +8 -1
- package/lib/commonjs/internal/adapter/event/PlayerEvents.js.map +1 -1
- package/lib/commonjs/manifest.json +1 -1
- package/lib/module/api/error/ContentProtectionError.js +2 -0
- package/lib/module/api/error/ContentProtectionError.js.map +1 -0
- package/lib/module/api/error/barrel.js +1 -0
- package/lib/module/api/error/barrel.js.map +1 -1
- package/lib/module/api/event/PlayerEvent.js +9 -0
- package/lib/module/api/event/PlayerEvent.js.map +1 -1
- package/lib/module/api/player/PlayerEventMap.js +1 -0
- package/lib/module/api/player/PlayerEventMap.js.map +1 -1
- package/lib/module/api/track/TextTrack.js +5 -2
- package/lib/module/api/track/TextTrack.js.map +1 -1
- package/lib/module/internal/THEOplayerView.js +5 -1
- package/lib/module/internal/THEOplayerView.js.map +1 -1
- package/lib/module/internal/adapter/WebEventForwarder.js +23 -1
- package/lib/module/internal/adapter/WebEventForwarder.js.map +1 -1
- package/lib/module/internal/adapter/event/PlayerEvents.js +6 -0
- package/lib/module/internal/adapter/event/PlayerEvents.js.map +1 -1
- package/lib/module/manifest.json +1 -1
- package/lib/typescript/api/error/ContentProtectionError.d.ts +53 -0
- package/lib/typescript/api/error/ContentProtectionError.d.ts.map +1 -0
- package/lib/typescript/api/error/barrel.d.ts +1 -0
- package/lib/typescript/api/error/barrel.d.ts.map +1 -1
- package/lib/typescript/api/event/PlayerEvent.d.ts +15 -1
- package/lib/typescript/api/event/PlayerEvent.d.ts.map +1 -1
- package/lib/typescript/api/player/PlayerEventMap.d.ts +7 -2
- package/lib/typescript/api/player/PlayerEventMap.d.ts.map +1 -1
- package/lib/typescript/api/track/TextTrack.d.ts.map +1 -1
- package/lib/typescript/internal/THEOplayerView.d.ts +1 -0
- package/lib/typescript/internal/THEOplayerView.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/WebEventForwarder.d.ts +1 -0
- package/lib/typescript/internal/adapter/WebEventForwarder.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/event/PlayerEvents.d.ts +5 -1
- package/lib/typescript/internal/adapter/event/PlayerEvents.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/event/native/NativePlayerEvent.d.ts +4 -1
- package/lib/typescript/internal/adapter/event/native/NativePlayerEvent.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api/error/ContentProtectionError.ts +58 -0
- package/src/api/error/barrel.ts +1 -0
- package/src/api/event/PlayerEvent.ts +16 -1
- package/src/api/player/PlayerEventMap.ts +7 -0
- package/src/api/track/TextTrack.ts +5 -2
- package/src/internal/THEOplayerView.tsx +8 -0
- package/src/internal/adapter/WebEventForwarder.ts +19 -0
- package/src/internal/adapter/event/PlayerEvents.ts +8 -0
- package/src/internal/adapter/event/native/NativePlayerEvent.ts +5 -0
- package/src/manifest.json +1 -1
|
@@ -42,46 +42,36 @@ class THEOplayerRCTPlayerAPI: NSObject, RCTBridgeModule {
|
|
|
42
42
|
|
|
43
43
|
@objc(setPaused:paused:)
|
|
44
44
|
func setPaused(_ node: NSNumber, paused: Bool) -> Void {
|
|
45
|
-
|
|
46
|
-
if
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Triggering play on TheoPlayer") }
|
|
53
|
-
player.play()
|
|
54
|
-
}
|
|
45
|
+
withViewAndPlayer(node) { _, player in
|
|
46
|
+
if paused && !player.paused {
|
|
47
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Triggering pause on TheoPlayer") }
|
|
48
|
+
player.pause()
|
|
49
|
+
} else if !paused && player.paused {
|
|
50
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Triggering play on TheoPlayer") }
|
|
51
|
+
player.play()
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
55
|
|
|
59
56
|
@objc(setAutoplay:autoplay:)
|
|
60
57
|
func setAutoplay(_ node: NSNumber, autoplay: Bool) -> Void {
|
|
61
|
-
|
|
62
|
-
if
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Changing TheoPlayer to \(autoplay ? "autoplay" : "not autoplay")") }
|
|
66
|
-
player.autoplay = autoplay
|
|
67
|
-
}
|
|
58
|
+
withViewAndPlayer(node) { _, player in
|
|
59
|
+
if autoplay != player.autoplay {
|
|
60
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Changing TheoPlayer to \(autoplay ? "autoplay" : "not autoplay")") }
|
|
61
|
+
player.autoplay = autoplay
|
|
68
62
|
}
|
|
69
63
|
}
|
|
70
64
|
}
|
|
71
65
|
|
|
72
66
|
@objc(setSource:src:)
|
|
73
67
|
func setSource(_ node: NSNumber, src: NSDictionary) -> Void {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
} else {
|
|
83
|
-
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Failed to update THEOplayer source.") }
|
|
84
|
-
}
|
|
68
|
+
withViewAndPlayer(node) { theView, player in
|
|
69
|
+
let (sourceDescription, metadataAndChapterTrackDescriptions) = THEOplayerRCTSourceDescriptionBuilder.buildSourceDescription(src)
|
|
70
|
+
self.triggerViewHierarchyValidation(player)
|
|
71
|
+
self.setNewSourceDescription(player: player, srcDescription: sourceDescription)
|
|
72
|
+
theView.processMetadataAndChapterTracks(trackDescriptions: metadataAndChapterTrackDescriptions)
|
|
73
|
+
} onFailure: {
|
|
74
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Failed to update THEOplayer source.") }
|
|
85
75
|
}
|
|
86
76
|
}
|
|
87
77
|
|
|
@@ -105,44 +95,41 @@ class THEOplayerRCTPlayerAPI: NSObject, RCTBridgeModule {
|
|
|
105
95
|
|
|
106
96
|
@objc(setABRConfig:abrConfig:)
|
|
107
97
|
func setABRConfig(_ node: NSNumber, abrConfig: NSDictionary) -> Void {
|
|
108
|
-
|
|
109
|
-
if
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
98
|
+
withViewAndPlayer(node) { _, player in
|
|
99
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Setting abrConfig on TheoPlayer") }
|
|
100
|
+
if let configuredTargetBuffer = abrConfig["targetBuffer"] as? Double {
|
|
101
|
+
player.abr.targetBuffer = configuredTargetBuffer
|
|
102
|
+
} else if let configuredTargetBuffer = abrConfig["targetBuffer"] as? Int {
|
|
103
|
+
player.abr.targetBuffer = Double(configuredTargetBuffer)
|
|
104
|
+
}
|
|
105
|
+
if let configuredPreferredPeakBitRate = abrConfig["preferredPeakBitRate"] as? Double {
|
|
106
|
+
player.abr.preferredPeakBitRate = configuredPreferredPeakBitRate
|
|
107
|
+
} else if let configuredPreferredPeakBitRate = abrConfig["preferredPeakBitRate"] as? Int {
|
|
108
|
+
player.abr.preferredPeakBitRate = Double(configuredPreferredPeakBitRate)
|
|
109
|
+
}
|
|
110
|
+
if let configuredPreferredMaximumResolution = abrConfig["preferredMaximumResolution"] as? [String:Double] {
|
|
111
|
+
if let width = configuredPreferredMaximumResolution["width"],
|
|
112
|
+
let height = configuredPreferredMaximumResolution["height"] {
|
|
113
|
+
player.abr.preferredMaximumResolution = CGSize(width: width, height: height)
|
|
121
114
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
} else if let configuredPreferredMaximumResolution = abrConfig["preferredMaximumResolution"] as? [String:Int] {
|
|
128
|
-
if let width = configuredPreferredMaximumResolution["width"],
|
|
129
|
-
let height = configuredPreferredMaximumResolution["height"] {
|
|
130
|
-
player.abr.preferredMaximumResolution = CGSize(width: Double(width), height: Double(height))
|
|
131
|
-
}
|
|
115
|
+
} else if let configuredPreferredMaximumResolution = abrConfig["preferredMaximumResolution"] as? [String:Int] {
|
|
116
|
+
if let width = configuredPreferredMaximumResolution["width"],
|
|
117
|
+
let height = configuredPreferredMaximumResolution["height"] {
|
|
118
|
+
player.abr.preferredMaximumResolution = CGSize(width: Double(width), height: Double(height))
|
|
132
119
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
let strategy = ABRStrategyConfiguration(type: abrType, metadata: abrMetadata)
|
|
144
|
-
player.abr.strategy = strategy
|
|
120
|
+
}
|
|
121
|
+
if let configuredStrategy = abrConfig["strategy"] as? String {
|
|
122
|
+
player.abr.strategy = ABRStrategyConfiguration(type: THEOplayerRCTTypeUtils.abrStrategyFromString(configuredStrategy))
|
|
123
|
+
} else if let configuredStrategy = abrConfig["strategy"] as? [String:Any] {
|
|
124
|
+
if let type = configuredStrategy["type"] as? String {
|
|
125
|
+
let abrType = THEOplayerRCTTypeUtils.abrStrategyFromString(type)
|
|
126
|
+
var abrMetadata: ABRMetadata?
|
|
127
|
+
if let metadata = configuredStrategy["metadata"] as? [String:Any],
|
|
128
|
+
let bitrate = metadata["bitrate"] as? Double {
|
|
129
|
+
abrMetadata = ABRMetadata(bitrate: bitrate)
|
|
145
130
|
}
|
|
131
|
+
let strategy = ABRStrategyConfiguration(type: abrType, metadata: abrMetadata)
|
|
132
|
+
player.abr.strategy = strategy
|
|
146
133
|
}
|
|
147
134
|
}
|
|
148
135
|
}
|
|
@@ -150,99 +137,77 @@ class THEOplayerRCTPlayerAPI: NSObject, RCTBridgeModule {
|
|
|
150
137
|
|
|
151
138
|
@objc(setCurrentTime:time:)
|
|
152
139
|
func setCurrentTime(_ node: NSNumber, time: NSNumber) -> Void {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Seeking to \(timeValue) on TheoPlayer") }
|
|
158
|
-
player.setCurrentTime(timeValue)
|
|
159
|
-
}
|
|
140
|
+
withViewAndPlayer(node) { _, player in
|
|
141
|
+
let timeValue = time.doubleValue * 0.001
|
|
142
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Seeking to \(timeValue) on TheoPlayer") }
|
|
143
|
+
player.setCurrentTime(timeValue)
|
|
160
144
|
}
|
|
161
145
|
}
|
|
162
146
|
|
|
163
147
|
@objc(goLive:)
|
|
164
148
|
func goLive(_ node: NSNumber) -> Void {
|
|
165
|
-
|
|
166
|
-
if
|
|
167
|
-
|
|
168
|
-
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] goLive on TheoPlayer") }
|
|
169
|
-
player.setCurrentTime(.infinity)
|
|
170
|
-
}
|
|
149
|
+
withViewAndPlayer(node) { _, player in
|
|
150
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] goLive on TheoPlayer") }
|
|
151
|
+
player.setCurrentTime(.infinity)
|
|
171
152
|
}
|
|
172
153
|
}
|
|
173
154
|
|
|
174
155
|
@objc(setMuted:muted:)
|
|
175
156
|
func setMuted(_ node: NSNumber, muted: Bool) -> Void {
|
|
176
|
-
|
|
177
|
-
if
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Changing TheoPlayer to \(muted ? "muted" : "not muted")") }
|
|
181
|
-
player.muted = muted
|
|
182
|
-
}
|
|
157
|
+
withViewAndPlayer(node) { _, player in
|
|
158
|
+
if player.muted != muted {
|
|
159
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Changing TheoPlayer to \(muted ? "muted" : "not muted")") }
|
|
160
|
+
player.muted = muted
|
|
183
161
|
}
|
|
184
162
|
}
|
|
185
163
|
}
|
|
186
164
|
|
|
187
165
|
@objc(setVolume:volume:)
|
|
188
166
|
func setVolume(_ node: NSNumber, volume: NSNumber) -> Void {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Changing TheoPlayer volume to \(newVolume)")}
|
|
195
|
-
player.volume = newVolume
|
|
196
|
-
}
|
|
167
|
+
withViewAndPlayer(node) { _, player in
|
|
168
|
+
let newVolume = Float(truncating: volume)
|
|
169
|
+
if player.volume != newVolume {
|
|
170
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Changing TheoPlayer volume to \(newVolume)")}
|
|
171
|
+
player.volume = newVolume
|
|
197
172
|
}
|
|
198
173
|
}
|
|
199
174
|
}
|
|
200
175
|
|
|
201
176
|
@objc(setPlaybackRate:playbackRate:)
|
|
202
177
|
func setPlaybackRate(_ node: NSNumber, playbackRate: NSNumber) -> Void {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Setting playbackRate on TheoPlayer to \(playbackRateValue)") }
|
|
209
|
-
player.playbackRate = playbackRateValue
|
|
210
|
-
}
|
|
178
|
+
withViewAndPlayer(node) { _, player in
|
|
179
|
+
let playbackRateValue = playbackRate.doubleValue
|
|
180
|
+
if player.playbackRate != playbackRateValue {
|
|
181
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Setting playbackRate on TheoPlayer to \(playbackRateValue)") }
|
|
182
|
+
player.playbackRate = playbackRateValue
|
|
211
183
|
}
|
|
212
184
|
}
|
|
213
185
|
}
|
|
214
186
|
|
|
215
187
|
@objc(setPresentationMode:presentationMode:)
|
|
216
188
|
func setPresentationMode(_ node: NSNumber, presentationMode: String) -> Void {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
theView.setPresentationMode(newPresentationMode: newPresentationMode)
|
|
221
|
-
}
|
|
189
|
+
withView(node) { theView in
|
|
190
|
+
let newPresentationMode: PresentationMode = THEOplayerRCTTypeUtils.presentationModeFromString(presentationMode)
|
|
191
|
+
theView.setPresentationMode(newPresentationMode: newPresentationMode)
|
|
222
192
|
}
|
|
223
193
|
}
|
|
224
194
|
|
|
225
195
|
@objc(setAspectRatio:ratio:)
|
|
226
196
|
func setAspectRatio(_ node: NSNumber, ratio: String) -> Void {
|
|
227
|
-
|
|
197
|
+
withViewAndPlayer(node) { _, player in
|
|
228
198
|
let newAspectRatio: AspectRatio = THEOplayerRCTTypeUtils.aspectRatioFromString(ratio)
|
|
229
|
-
if
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Changing TheoPlayer's aspectRatio to \(ratio)") }
|
|
233
|
-
player.aspectRatio = newAspectRatio
|
|
234
|
-
}
|
|
199
|
+
if player.aspectRatio != newAspectRatio {
|
|
200
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Changing TheoPlayer's aspectRatio to \(ratio)") }
|
|
201
|
+
player.aspectRatio = newAspectRatio
|
|
235
202
|
}
|
|
236
203
|
}
|
|
237
204
|
}
|
|
238
205
|
|
|
239
206
|
@objc(setPipConfig:pipConfig:)
|
|
240
207
|
func setPipConfig(_ node: NSNumber, pipConfig: NSDictionary) -> Void {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
theView.pipConfig = pipConfig
|
|
245
|
-
}
|
|
208
|
+
withView(node) { theView in
|
|
209
|
+
let pipConfig = self.parsePipConfig(configDict: pipConfig)
|
|
210
|
+
theView.pipConfig = pipConfig
|
|
246
211
|
}
|
|
247
212
|
}
|
|
248
213
|
|
|
@@ -255,11 +220,9 @@ class THEOplayerRCTPlayerAPI: NSObject, RCTBridgeModule {
|
|
|
255
220
|
|
|
256
221
|
@objc(setBackgroundAudioConfig:backgroundAudioConfig:)
|
|
257
222
|
func setBackgroundAudioConfig(_ node: NSNumber, backgroundAudioConfig: NSDictionary) -> Void {
|
|
258
|
-
|
|
223
|
+
withView(node) { theView in
|
|
259
224
|
let newBackgroundAudioConfig: BackgroundAudioConfig = self.parseBackgroundAudioConfig(configDict: backgroundAudioConfig)
|
|
260
|
-
|
|
261
|
-
theView.backgroundAudioConfig = newBackgroundAudioConfig
|
|
262
|
-
}
|
|
225
|
+
theView.backgroundAudioConfig = newBackgroundAudioConfig
|
|
263
226
|
}
|
|
264
227
|
}
|
|
265
228
|
|
|
@@ -276,24 +239,21 @@ class THEOplayerRCTPlayerAPI: NSObject, RCTBridgeModule {
|
|
|
276
239
|
|
|
277
240
|
@objc(setSelectedTextTrack:uid:)
|
|
278
241
|
func setSelectedTextTrack(_ node: NSNumber, uid: NSNumber) -> Void {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
} else if textTrack.mode == TextTrackMode.showing {
|
|
295
|
-
textTrack.mode = TextTrackMode.disabled
|
|
296
|
-
}
|
|
242
|
+
withViewAndPlayer(node) { _, player in
|
|
243
|
+
let uidValue = uid.intValue
|
|
244
|
+
let textTracks: TextTrackList = player.textTracks
|
|
245
|
+
let textTrackCount = textTracks.count
|
|
246
|
+
guard textTrackCount > 0 else {
|
|
247
|
+
return
|
|
248
|
+
}
|
|
249
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Showing textTrack \(uidValue) on TheoPlayer") }
|
|
250
|
+
for i in 0..<textTrackCount {
|
|
251
|
+
guard i < textTracks.count else { break }
|
|
252
|
+
let textTrack: TextTrack = textTracks.get(i)
|
|
253
|
+
if textTrack.uid == uidValue {
|
|
254
|
+
textTrack.mode = TextTrackMode.showing
|
|
255
|
+
} else if textTrack.mode == TextTrackMode.showing {
|
|
256
|
+
textTrack.mode = TextTrackMode.disabled
|
|
297
257
|
}
|
|
298
258
|
}
|
|
299
259
|
}
|
|
@@ -301,84 +261,75 @@ class THEOplayerRCTPlayerAPI: NSObject, RCTBridgeModule {
|
|
|
301
261
|
|
|
302
262
|
@objc(setSelectedAudioTrack:uid:)
|
|
303
263
|
func setSelectedAudioTrack(_ node: NSNumber, uid: NSNumber) -> Void {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
let audioTrack: MediaTrack = audioTracks.get(i)
|
|
317
|
-
audioTrack.enabled = (audioTrack.uid == uidValue)
|
|
318
|
-
}
|
|
264
|
+
withViewAndPlayer(node) { _, player in
|
|
265
|
+
let uidValue = uid.intValue
|
|
266
|
+
let audioTracks: AudioTrackList = player.audioTracks
|
|
267
|
+
let audioTrackCount = audioTracks.count
|
|
268
|
+
guard audioTrackCount > 0 else {
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Enabling audioTrack \(uidValue) on TheoPlayer") }
|
|
272
|
+
for i in 0..<audioTrackCount {
|
|
273
|
+
guard i < audioTracks.count else { break }
|
|
274
|
+
let audioTrack: MediaTrack = audioTracks.get(i)
|
|
275
|
+
audioTrack.enabled = (audioTrack.uid == uidValue)
|
|
319
276
|
}
|
|
320
277
|
}
|
|
321
278
|
}
|
|
322
279
|
|
|
323
280
|
@objc(setSelectedVideoTrack:uid:)
|
|
324
281
|
func setSelectedVideoTrack(_ node: NSNumber, uid: NSNumber) -> Void {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
let videoTrack: MediaTrack = videoTracks.get(i)
|
|
338
|
-
videoTrack.enabled = (videoTrack.uid == uidValue)
|
|
339
|
-
}
|
|
282
|
+
withViewAndPlayer(node) { _, player in
|
|
283
|
+
let uidValue = uid.intValue
|
|
284
|
+
let videoTracks: VideoTrackList = player.videoTracks
|
|
285
|
+
let videoTrackCount = videoTracks.count
|
|
286
|
+
guard videoTrackCount > 0 else {
|
|
287
|
+
return
|
|
288
|
+
}
|
|
289
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Enabling videoTrack \(uidValue) on TheoPlayer") }
|
|
290
|
+
for i in 0..<videoTrackCount {
|
|
291
|
+
guard i < videoTracks.count else { break }
|
|
292
|
+
let videoTrack: MediaTrack = videoTracks.get(i)
|
|
293
|
+
videoTrack.enabled = (videoTrack.uid == uidValue)
|
|
340
294
|
}
|
|
341
295
|
}
|
|
342
296
|
}
|
|
343
297
|
|
|
344
298
|
@objc(setTargetVideoQuality:uids:)
|
|
345
299
|
func setTargetVideoQuality(_ node: NSNumber, uids: [NSNumber]) -> Void {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
300
|
+
withViewAndPlayer(node) { _, player in
|
|
301
|
+
let videoTracks: VideoTrackList = player.videoTracks
|
|
302
|
+
let videoTrackCount = videoTracks.count
|
|
303
|
+
guard videoTrackCount > 0 else {
|
|
304
|
+
return
|
|
305
|
+
}
|
|
306
|
+
var activeVideoTrack: VideoTrack?
|
|
307
|
+
for i in 0..<videoTrackCount {
|
|
308
|
+
guard i < videoTracks.count else { break }
|
|
309
|
+
let videoTrack: MediaTrack = videoTracks.get(i)
|
|
310
|
+
if videoTrack.enabled {
|
|
311
|
+
activeVideoTrack = videoTrack as? VideoTrack
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if let foundTrack = activeVideoTrack {
|
|
315
|
+
let requestedBandwidths = Set(uids.map { $0.intValue })
|
|
316
|
+
let currentBandwidths = Set(foundTrack.targetQualities?.map { $0.bandwidth } ?? [])
|
|
317
|
+
guard requestedBandwidths != currentBandwidths else {
|
|
318
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] targetQualities: \(uids) already set on active videotrack. Skipping update.") }
|
|
352
319
|
return
|
|
353
320
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
guard
|
|
357
|
-
let
|
|
358
|
-
|
|
359
|
-
activeVideoTrack = videoTrack as? VideoTrack
|
|
360
|
-
}
|
|
321
|
+
let qualityCount = foundTrack.qualities.count
|
|
322
|
+
let matchingQualities = (0..<qualityCount).compactMap { index -> Quality? in
|
|
323
|
+
guard index < foundTrack.qualities.count else { return nil }
|
|
324
|
+
let quality = foundTrack.qualities.get(index)
|
|
325
|
+
return uids.contains(where: { $0.intValue == quality.bandwidth }) ? quality : nil
|
|
361
326
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
let qualityCount = foundTrack.qualities.count
|
|
370
|
-
let matchingQualities = (0..<qualityCount).compactMap { index -> Quality? in
|
|
371
|
-
guard index < foundTrack.qualities.count else { return nil }
|
|
372
|
-
let quality = foundTrack.qualities.get(index)
|
|
373
|
-
return uids.contains(where: { $0.intValue == quality.bandwidth }) ? quality : nil
|
|
374
|
-
}
|
|
375
|
-
foundTrack.targetQualities = matchingQualities.isEmpty ? nil : matchingQualities
|
|
376
|
-
if DEBUG_PLAYER_API {
|
|
377
|
-
if matchingQualities.count > 0 {
|
|
378
|
-
PrintUtils.printLog(logText: "[NATIVE] targetQualities: \(uids) set on active videotrack. (matching: \(matchingQualities.map(\.bandwidth)))")
|
|
379
|
-
} else {
|
|
380
|
-
PrintUtils.printLog(logText: "[NATIVE] targetQualities: \(uids) set on active videotrack. (no match or empty) => no quality restriction.")
|
|
381
|
-
}
|
|
327
|
+
foundTrack.targetQualities = matchingQualities.isEmpty ? nil : matchingQualities
|
|
328
|
+
if DEBUG_PLAYER_API {
|
|
329
|
+
if matchingQualities.count > 0 {
|
|
330
|
+
PrintUtils.printLog(logText: "[NATIVE] targetQualities: \(uids) set on active videotrack. (matching: \(matchingQualities.map(\.bandwidth)))")
|
|
331
|
+
} else {
|
|
332
|
+
PrintUtils.printLog(logText: "[NATIVE] targetQualities: \(uids) set on active videotrack. (no match or empty) => no quality restriction.")
|
|
382
333
|
}
|
|
383
334
|
}
|
|
384
335
|
}
|
|
@@ -387,67 +338,58 @@ class THEOplayerRCTPlayerAPI: NSObject, RCTBridgeModule {
|
|
|
387
338
|
|
|
388
339
|
@objc(setPreload:type:)
|
|
389
340
|
func setPreload(_ node: NSNumber, type: String) -> Void {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Changing TheoPlayer preload type to \(type)") }
|
|
396
|
-
player.preload = preloadType
|
|
397
|
-
}
|
|
341
|
+
withViewAndPlayer(node) { _, player in
|
|
342
|
+
let preloadType = THEOplayerRCTTypeUtils.preloadTypeFromString(type)
|
|
343
|
+
if player.preload != preloadType {
|
|
344
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Changing TheoPlayer preload type to \(type)") }
|
|
345
|
+
player.preload = preloadType
|
|
398
346
|
}
|
|
399
347
|
}
|
|
400
348
|
}
|
|
401
349
|
|
|
402
350
|
@objc(setTextTrackStyle:textTrackStyle:)
|
|
403
351
|
func setTextTrackStyle(_ node: NSNumber, textTrackStyle: NSDictionary) -> Void {
|
|
404
|
-
|
|
405
|
-
if let
|
|
406
|
-
let
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
if let marginLeft = textTrackStyle[TTS_PROP_MARGIN_LEFT] as? Int {
|
|
436
|
-
player.textTrackStyle?.marginLeft = [TextTrackStyleRuleNumber(marginLeft)]
|
|
437
|
-
}
|
|
352
|
+
withViewAndPlayer(node) { _, player in
|
|
353
|
+
if let bgColorMap = textTrackStyle[TTS_PROP_BACKGROUND_COLOR] as? [String:Any],
|
|
354
|
+
let r = bgColorMap[TTS_PROP_COLOR_R] as? Int,
|
|
355
|
+
let g = bgColorMap[TTS_PROP_COLOR_G] as? Int,
|
|
356
|
+
let b = bgColorMap[TTS_PROP_COLOR_B] as? Int,
|
|
357
|
+
let a = bgColorMap[TTS_PROP_COLOR_A] as? Int {
|
|
358
|
+
let bgColor = UIColor(red: CGFloat(r)/255.0, green: CGFloat(g)/255.0, blue: CGFloat(b)/255.0, alpha: CGFloat(a)/255.0)
|
|
359
|
+
player.textTrackStyle?.backgroundColor = [TextTrackStyleRuleColor(bgColor)]
|
|
360
|
+
}
|
|
361
|
+
if let fontColorMap = textTrackStyle[TTS_PROP_FONT_COLOR] as? [String:Any],
|
|
362
|
+
let r = fontColorMap[TTS_PROP_COLOR_R] as? Int,
|
|
363
|
+
let g = fontColorMap[TTS_PROP_COLOR_G] as? Int,
|
|
364
|
+
let b = fontColorMap[TTS_PROP_COLOR_B] as? Int,
|
|
365
|
+
let a = fontColorMap[TTS_PROP_COLOR_A] as? Int {
|
|
366
|
+
let fontColor = UIColor(red: CGFloat(r)/255.0, green: CGFloat(g)/255.0, blue: CGFloat(b)/255.0, alpha: CGFloat(a)/255.0)
|
|
367
|
+
player.textTrackStyle?.fontColor = [TextTrackStyleRuleColor(fontColor)]
|
|
368
|
+
}
|
|
369
|
+
if let edgeStyle = textTrackStyle[TTS_PROP_EDGE_STYLE] as? String {
|
|
370
|
+
player.textTrackStyle?.edgeStyle = [TextTrackStyleRuleString(THEOplayerRCTTypeUtils.textTrackEdgeStyleStringFromString(edgeStyle))]
|
|
371
|
+
}
|
|
372
|
+
if let fontFamily = textTrackStyle[TTS_PROP_FONT_FAMILY] as? String {
|
|
373
|
+
player.textTrackStyle?.fontFamily = [TextTrackStyleRuleString(fontFamily)]
|
|
374
|
+
}
|
|
375
|
+
if let fontSize = textTrackStyle[TTS_PROP_FONT_SIZE] as? Int {
|
|
376
|
+
player.textTrackStyle?.fontSize = [TextTrackStyleRuleNumber(fontSize)]
|
|
377
|
+
}
|
|
378
|
+
if let marginTop = textTrackStyle[TTS_PROP_MARGIN_TOP] as? Int {
|
|
379
|
+
player.textTrackStyle?.marginTop = [TextTrackStyleRuleNumber(marginTop)]
|
|
380
|
+
}
|
|
381
|
+
if let marginLeft = textTrackStyle[TTS_PROP_MARGIN_LEFT] as? Int {
|
|
382
|
+
player.textTrackStyle?.marginLeft = [TextTrackStyleRuleNumber(marginLeft)]
|
|
438
383
|
}
|
|
439
384
|
}
|
|
440
385
|
}
|
|
441
386
|
|
|
442
387
|
@objc(setKeepScreenOn:keepScreenOn:)
|
|
443
388
|
func setKeepScreenOn(_ node: NSNumber, keepScreenOn: Bool) -> Void {
|
|
444
|
-
|
|
445
|
-
if
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Changing TheoPlayer preventsDisplaySleepDuringVideoPlayback to \(keepScreenOn)") }
|
|
449
|
-
player.preventsDisplaySleepDuringVideoPlayback = keepScreenOn
|
|
450
|
-
}
|
|
389
|
+
withViewAndPlayer(node) { _, player in
|
|
390
|
+
if player.preventsDisplaySleepDuringVideoPlayback != keepScreenOn {
|
|
391
|
+
if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Changing TheoPlayer preventsDisplaySleepDuringVideoPlayback to \(keepScreenOn)") }
|
|
392
|
+
player.preventsDisplaySleepDuringVideoPlayback = keepScreenOn
|
|
451
393
|
}
|
|
452
394
|
}
|
|
453
395
|
}
|
|
@@ -480,10 +422,8 @@ class THEOplayerRCTPlayerAPI: NSObject, RCTBridgeModule {
|
|
|
480
422
|
|
|
481
423
|
@objc(willUnmount:)
|
|
482
424
|
func willUnmount(_ node: NSNumber) -> Void {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
theView.willUnmount()
|
|
486
|
-
}
|
|
425
|
+
withView(node) { theView in
|
|
426
|
+
theView.willUnmount()
|
|
487
427
|
}
|
|
488
428
|
}
|
|
489
429
|
}
|
|
@@ -116,7 +116,7 @@ class THEOplayerRCTTrackMetadataAggregator {
|
|
|
116
116
|
entry[PROP_STARTTIME] = THEOplayerRCTTypeUtils.encodeInfNan(textTrackCue.startTime * 1000)
|
|
117
117
|
entry[PROP_ENDTIME] = THEOplayerRCTTypeUtils.encodeInfNan(textTrackCue.endTime * 1000)
|
|
118
118
|
if let content = textTrackCue.content {
|
|
119
|
-
entry[PROP_CUE_CONTENT] = content
|
|
119
|
+
entry[PROP_CUE_CONTENT] = THEOplayerRCTTypeUtils.bridgeSafe(content)
|
|
120
120
|
} else if let contentString = textTrackCue.contentString {
|
|
121
121
|
entry[PROP_CUE_CONTENT] = contentString
|
|
122
122
|
}
|
|
@@ -150,7 +150,7 @@ class THEOplayerRCTTrackMetadataAggregator {
|
|
|
150
150
|
} catch {
|
|
151
151
|
do {
|
|
152
152
|
// try reading as data
|
|
153
|
-
attributesEntry[key] = try customAttributes.getBytes(for: key)
|
|
153
|
+
attributesEntry[key] = THEOplayerRCTTypeUtils.bridgeSafe(try customAttributes.getBytes(for: key))
|
|
154
154
|
} catch {
|
|
155
155
|
print("Unable to extract customAttribute from DateRange cue. Content is limited to String, Double or Data.")
|
|
156
156
|
}
|