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
|
@@ -17,6 +17,22 @@ class THEOplayerRCTTypeUtils {
|
|
|
17
17
|
}
|
|
18
18
|
return value
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
/// Converts a value into a bridge-safe representation: the RN bridge drops values it cannot
|
|
22
|
+
/// serialize to JSON (e.g. `Data`, which becomes `null`). Binary payloads are converted to
|
|
23
|
+
/// number arrays, matching the byte-array shape used by the Android bridge.
|
|
24
|
+
class func bridgeSafe(_ value: Any) -> Any {
|
|
25
|
+
switch value {
|
|
26
|
+
case let data as Data:
|
|
27
|
+
return data.map { Int($0) }
|
|
28
|
+
case let dictionary as [String: Any]:
|
|
29
|
+
return dictionary.mapValues { bridgeSafe($0) }
|
|
30
|
+
case let array as [Any]:
|
|
31
|
+
return array.map { bridgeSafe($0) }
|
|
32
|
+
default:
|
|
33
|
+
return value
|
|
34
|
+
}
|
|
35
|
+
}
|
|
20
36
|
|
|
21
37
|
class func preloadTypeFromString(_ type: String) -> Preload {
|
|
22
38
|
switch type {
|
|
@@ -305,7 +305,7 @@ public class THEOplayerRCTView: UIView {
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
// trigger different feature managers to reflect the current state
|
|
308
|
-
self.nowPlayingManager.
|
|
308
|
+
self.nowPlayingManager.updateNowPlayingInfo()
|
|
309
309
|
self.remoteCommandsManager.updateRemoteCommands()
|
|
310
310
|
self.pipControlsManager.updatePipControls()
|
|
311
311
|
}
|
|
@@ -470,6 +470,12 @@ public class THEOplayerRCTView: UIView {
|
|
|
470
470
|
if DEBUG_VIEW { PrintUtils.printLog(logText: "[NATIVE] nativeCanPlay prop set.") }
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
+
@objc(setOnNativeContentProtectionError:)
|
|
474
|
+
func setOnNativeContentProtectionError(nativeContentProtectionError: @escaping RCTDirectEventBlock) {
|
|
475
|
+
self.mainEventHandler.onNativeContentProtectionError = nativeContentProtectionError
|
|
476
|
+
if DEBUG_VIEW { PrintUtils.printLog(logText: "[NATIVE] nativeContentProtectionError prop set.") }
|
|
477
|
+
}
|
|
478
|
+
|
|
473
479
|
@objc(setOnNativeDimensionChange:)
|
|
474
480
|
func setOnNativeDimensionChange(nativeDimensionChange: @escaping RCTDirectEventBlock) {
|
|
475
481
|
self.mainEventHandler.onNativeDimensionChange = nativeDimensionChange
|
|
@@ -14,60 +14,61 @@ extension THEOplayerRCTAdsAPI {
|
|
|
14
14
|
#if canImport(THEOplayerGoogleIMAIntegration)
|
|
15
15
|
@objc(daiSnapback:resolver:rejecter:)
|
|
16
16
|
func daiSnapback(_ node: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
17
|
-
|
|
18
|
-
if let
|
|
19
|
-
let ads = theView.ads(),
|
|
20
|
-
let dai = ads.dai {
|
|
17
|
+
withViewAndAds(node) { _, ads in
|
|
18
|
+
if let dai = ads.dai {
|
|
21
19
|
resolve(dai.snapback)
|
|
22
20
|
} else {
|
|
23
21
|
reject(ERROR_CODE_DAI_ACCESS_FAILURE, ERROR_MESSAGE_DAI_ACCESS_FAILURE, nil)
|
|
24
|
-
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not retrieve dai snapback status (
|
|
22
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not retrieve dai snapback status (DAI module unavailable).") }
|
|
25
23
|
}
|
|
24
|
+
} onFailure: {
|
|
25
|
+
reject(ERROR_CODE_ADS_ACCESS_FAILURE, ERROR_MESSAGE_ADS_ACCESS_FAILURE, nil)
|
|
26
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not retrieve dai snapback status (ads module unavailable).") }
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
@objc(daiSetSnapback:enabled:)
|
|
30
31
|
func daiSetSnapback(_ node: NSNumber, enabled: Bool) -> Void {
|
|
31
|
-
|
|
32
|
-
if
|
|
33
|
-
let ads = theView.ads(),
|
|
34
|
-
var dai = ads.dai {
|
|
32
|
+
withViewAndAds(node) { _, ads in
|
|
33
|
+
if var dai = ads.dai {
|
|
35
34
|
dai.snapback = enabled
|
|
36
|
-
} else {
|
|
37
|
-
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not update dai snapback status (ads DAI module unavailable).") }
|
|
38
35
|
}
|
|
36
|
+
} onFailure: {
|
|
37
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not update dai snapback status (ads DAI module unavailable).") }
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
@objc(daiContentTimeForStreamTime:time:resolver:rejecter:)
|
|
43
42
|
func daiContentTimeForStreamTime(_ node: NSNumber, timeValue: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
44
|
-
|
|
45
|
-
if let
|
|
46
|
-
let ads = theView.ads(),
|
|
47
|
-
let dai = ads.dai {
|
|
43
|
+
withViewAndAds(node) { _, ads in
|
|
44
|
+
if let dai = ads.dai {
|
|
48
45
|
let streamTime = timeValue.doubleValue * 0.001 // msec -> sec
|
|
49
46
|
let contentTime = dai.contentTime(from: streamTime) * 1000.0 // sec -> msec
|
|
50
47
|
resolve(contentTime)
|
|
51
48
|
} else {
|
|
52
49
|
reject(ERROR_CODE_DAI_ACCESS_FAILURE, ERROR_MESSAGE_DAI_ACCESS_FAILURE, nil)
|
|
53
|
-
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not convert stream time to content time (
|
|
50
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not convert stream time to content time (DAI module unavailable).") }
|
|
54
51
|
}
|
|
52
|
+
} onFailure: {
|
|
53
|
+
reject(ERROR_CODE_ADS_ACCESS_FAILURE, ERROR_MESSAGE_ADS_ACCESS_FAILURE, nil)
|
|
54
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not convert stream time to content time (ads module unavailable).") }
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
@objc(daiStreamTimeForContentTime:time:resolver:rejecter:)
|
|
59
59
|
func daiStreamTimeForContentTime(_ node: NSNumber, timeValue: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
60
|
-
|
|
61
|
-
if let
|
|
62
|
-
let ads = theView.ads(),
|
|
63
|
-
let dai = ads.dai {
|
|
60
|
+
withViewAndAds(node) { _, ads in
|
|
61
|
+
if let dai = ads.dai {
|
|
64
62
|
let contentTime = timeValue.doubleValue * 0.001 // msec -> sec
|
|
65
63
|
let streamTime = dai.streamTime(from: contentTime) * 1000.0 // sec -> msec
|
|
66
64
|
resolve(streamTime)
|
|
67
65
|
} else {
|
|
68
66
|
reject(ERROR_CODE_DAI_ACCESS_FAILURE, ERROR_MESSAGE_DAI_ACCESS_FAILURE, nil)
|
|
69
|
-
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not convert content time to stream time (
|
|
67
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not convert content time to stream time (DAI module unavailable).") }
|
|
70
68
|
}
|
|
69
|
+
} onFailure: {
|
|
70
|
+
reject(ERROR_CODE_ADS_ACCESS_FAILURE, ERROR_MESSAGE_ADS_ACCESS_FAILURE, nil)
|
|
71
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not convert content time to stream time (ads module unavailable).") }
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -13,12 +13,10 @@ extension THEOplayerRCTAdsAPI {
|
|
|
13
13
|
#if canImport(THEOplayerGoogleIMAIntegration)
|
|
14
14
|
@objc(addFriendlyObstruction:obstruction:)
|
|
15
15
|
func addFriendlyObstruction(_ node: NSNumber, obstruction: NSDictionary) {
|
|
16
|
-
|
|
16
|
+
withViewAndAds(node) { _, ads in
|
|
17
17
|
if let obstructionNode = obstruction[PROP_OMID_VIEW] as? NSNumber,
|
|
18
18
|
let purposeString = obstruction[PROP_OMID_PURPOSE] as? String,
|
|
19
|
-
let
|
|
20
|
-
let obstructionView = self.bridge.uiManager.view(forReactTag: obstructionNode),
|
|
21
|
-
let ads = theView.ads() {
|
|
19
|
+
let obstructionView = self.bridge.uiManager.view(forReactTag: obstructionNode) {
|
|
22
20
|
let obstruction = OmidFriendlyObstruction(view: obstructionView,
|
|
23
21
|
purpose: THEOplayerRCTTypeUtils.omidFriendlyObstructionPurposeFromString(purposeString),
|
|
24
22
|
detailedReason: obstruction[PROP_OMID_REASON] as? String)
|
|
@@ -29,11 +27,8 @@ extension THEOplayerRCTAdsAPI {
|
|
|
29
27
|
|
|
30
28
|
@objc(removeAllFriendlyObstructions:)
|
|
31
29
|
func removeAllFriendlyObstructions(_ node: NSNumber) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
let ads = theView.ads() {
|
|
35
|
-
ads.omid.removeFriendlyObstructions()
|
|
36
|
-
}
|
|
30
|
+
withViewAndAds(node) { _, ads in
|
|
31
|
+
ads.omid.removeFriendlyObstructions()
|
|
37
32
|
}
|
|
38
33
|
}
|
|
39
34
|
|
|
@@ -38,90 +38,79 @@ class THEOplayerRCTAdsAPI: NSObject, RCTBridgeModule {
|
|
|
38
38
|
@objc(skip:)
|
|
39
39
|
func skip(_ node: NSNumber) -> Void {
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} else {
|
|
46
|
-
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not skip ad (ads module unavailable).") }
|
|
47
|
-
}
|
|
41
|
+
withViewAndAds(node) { _, ads in
|
|
42
|
+
ads.skip()
|
|
43
|
+
} onFailure: {
|
|
44
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not skip ad (ads module unavailable).") }
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
@objc(playing:resolver:rejecter:)
|
|
52
49
|
func playing(_ node: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
reject(ERROR_CODE_ADS_ACCESS_FAILURE, ERROR_MESSAGE_ADS_ACCESS_FAILURE, nil)
|
|
59
|
-
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not skip ad (ads module unavailable).") }
|
|
60
|
-
}
|
|
50
|
+
withViewAndAds(node) { _, ads in
|
|
51
|
+
resolve(ads.playing)
|
|
52
|
+
} onFailure: {
|
|
53
|
+
reject(ERROR_CODE_ADS_ACCESS_FAILURE, ERROR_MESSAGE_ADS_ACCESS_FAILURE, nil)
|
|
54
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not skip ad (ads module unavailable).") }
|
|
61
55
|
}
|
|
62
56
|
}
|
|
63
57
|
|
|
64
58
|
@objc(currentAdBreak:resolver:rejecter:)
|
|
65
59
|
func currentAdBreak(_ node: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
66
|
-
|
|
67
|
-
if let
|
|
68
|
-
let ads = theView.ads(),
|
|
69
|
-
let currentAdBreak = ads.currentAdBreak {
|
|
60
|
+
withViewAndAds(node) { _, ads in
|
|
61
|
+
if let currentAdBreak = ads.currentAdBreak {
|
|
70
62
|
resolve(THEOplayerRCTAdAdapter.fromAdBreak(adBreak:currentAdBreak))
|
|
71
63
|
} else {
|
|
72
|
-
reject(
|
|
73
|
-
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not retrieve current adbreak (
|
|
64
|
+
reject(ERROR_CODE_ADS_GET_CURRENT_ADBREAK_UNDEFINED, ERROR_MESSAGE_ADS_GET_CURRENT_ADBREAK_UNDEFINED, nil)
|
|
65
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not retrieve current adbreak (no current adbreak).") }
|
|
74
66
|
}
|
|
67
|
+
} onFailure: {
|
|
68
|
+
reject(ERROR_CODE_ADS_ACCESS_FAILURE, ERROR_MESSAGE_ADS_ACCESS_FAILURE, nil)
|
|
69
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not retrieve current adbreak (ads module unavailable).") }
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
72
|
|
|
78
73
|
@objc(currentAds:resolver:rejecter:)
|
|
79
74
|
func currentAds(_ node: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
for ad in currentAdsArray {
|
|
86
|
-
currentAds.append(THEOplayerRCTAdAdapter.fromAd(ad: ad))
|
|
87
|
-
}
|
|
88
|
-
resolve(currentAds)
|
|
89
|
-
} else {
|
|
90
|
-
reject(ERROR_CODE_ADS_ACCESS_FAILURE, ERROR_MESSAGE_ADS_ACCESS_FAILURE, nil)
|
|
91
|
-
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not retrieve current ad (ads module unavailable).") }
|
|
75
|
+
withViewAndAds(node) { _, ads in
|
|
76
|
+
let currentAdsArray = ads.currentAds
|
|
77
|
+
var currentAds: [[String:Any]] = []
|
|
78
|
+
for ad in currentAdsArray {
|
|
79
|
+
currentAds.append(THEOplayerRCTAdAdapter.fromAd(ad: ad))
|
|
92
80
|
}
|
|
81
|
+
resolve(currentAds)
|
|
82
|
+
} onFailure: {
|
|
83
|
+
reject(ERROR_CODE_ADS_ACCESS_FAILURE, ERROR_MESSAGE_ADS_ACCESS_FAILURE, nil)
|
|
84
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not retrieve current ad (ads module unavailable).") }
|
|
93
85
|
}
|
|
94
86
|
}
|
|
95
87
|
|
|
96
88
|
@objc(scheduledAdBreaks:resolver:rejecter:)
|
|
97
89
|
func scheduledAdBreaks(_ node: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
for adbreak in currentAdBreaksArray {
|
|
104
|
-
currentAdBreaks.append(THEOplayerRCTAdAdapter.fromAdBreak(adBreak: adbreak))
|
|
105
|
-
}
|
|
106
|
-
resolve(currentAdBreaks)
|
|
107
|
-
} else {
|
|
108
|
-
reject(ERROR_CODE_ADS_ACCESS_FAILURE, ERROR_MESSAGE_ADS_ACCESS_FAILURE, nil)
|
|
109
|
-
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not retrieve current ad (ads module unavailable).") }
|
|
90
|
+
withViewAndAds(node) { _, ads in
|
|
91
|
+
let currentAdBreaksArray = ads.scheduledAdBreaks
|
|
92
|
+
var currentAdBreaks: [[String:Any]] = []
|
|
93
|
+
for adbreak in currentAdBreaksArray {
|
|
94
|
+
currentAdBreaks.append(THEOplayerRCTAdAdapter.fromAdBreak(adBreak: adbreak))
|
|
110
95
|
}
|
|
96
|
+
resolve(currentAdBreaks)
|
|
97
|
+
} onFailure: {
|
|
98
|
+
reject(ERROR_CODE_ADS_ACCESS_FAILURE, ERROR_MESSAGE_ADS_ACCESS_FAILURE, nil)
|
|
99
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not retrieve current ad (ads module unavailable).") }
|
|
111
100
|
}
|
|
112
101
|
}
|
|
113
102
|
|
|
114
103
|
@objc(schedule:ad:)
|
|
115
104
|
func schedule(_ node: NSNumber, adDict: NSDictionary) -> Void {
|
|
116
|
-
|
|
117
|
-
if let
|
|
118
|
-
let adData = adDict as? [String:Any],
|
|
119
|
-
let ads = theView.ads(),
|
|
105
|
+
withViewAndAds(node) { _, ads in
|
|
106
|
+
if let adData = adDict as? [String:Any],
|
|
120
107
|
let adDescription = THEOplayerRCTSourceDescriptionBuilder.buildSingleAdDescription(adData) {
|
|
121
108
|
ads.schedule(adDescription: adDescription)
|
|
122
109
|
} else {
|
|
123
|
-
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not schedule new ad.") }
|
|
110
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not schedule new ad (invalid ad description).") }
|
|
124
111
|
}
|
|
112
|
+
} onFailure: {
|
|
113
|
+
if DEBUG_ADS_API { PrintUtils.printLog(logText: "[NATIVE] Could not schedule new ad.") }
|
|
125
114
|
}
|
|
126
115
|
}
|
|
127
116
|
|
|
@@ -32,7 +32,7 @@ class THEOplayerRCTBackgroundAudioManager: NSObject, BackgroundPlaybackDelegate
|
|
|
32
32
|
return false
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
view.nowPlayingManager.
|
|
35
|
+
view.nowPlayingManager.updateNowPlayingInfo()
|
|
36
36
|
return view.backgroundAudioConfig.enabled
|
|
37
37
|
}
|
|
38
38
|
return false
|
|
@@ -7,7 +7,9 @@ import MediaPlayer
|
|
|
7
7
|
class THEOplayerRCTNowPlayingManager {
|
|
8
8
|
// MARK: Members
|
|
9
9
|
private weak var player: THEOplayer?
|
|
10
|
-
private
|
|
10
|
+
private let nowPlayingQueue = DispatchQueue(label: "com.theoplayer.reactnative.nowplayinginfo")
|
|
11
|
+
private var nowPlayingInfoStorage = [String : Any]()
|
|
12
|
+
private var nowPlayingInfoGeneration: Int = 0
|
|
11
13
|
|
|
12
14
|
// MARK: player Listeners
|
|
13
15
|
private var durationChangeListener: EventListener?
|
|
@@ -25,12 +27,12 @@ class THEOplayerRCTNowPlayingManager {
|
|
|
25
27
|
// update elapsed time on close
|
|
26
28
|
if let player = self.player {
|
|
27
29
|
updateCurrentTime(player.currentTime)
|
|
28
|
-
self.
|
|
30
|
+
self.processNowPlayingInfoToInfoCenter()
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
// clear nowPlayingInfo
|
|
32
|
-
self.
|
|
33
|
-
self.
|
|
34
|
+
self.clearNowPlayingInfoStorage()
|
|
35
|
+
self.clearNowPlayingInfoOnInfoCenter()
|
|
34
36
|
|
|
35
37
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] Destroy, nowPlayingInfo cleared on infoCenter.") }
|
|
36
38
|
}
|
|
@@ -61,36 +63,77 @@ class THEOplayerRCTNowPlayingManager {
|
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
func
|
|
65
|
-
// Reset any existing playing info
|
|
66
|
-
|
|
66
|
+
func updateNowPlayingInfo() {
|
|
67
|
+
// Reset any existing playing info; this invalidates any artwork fetch still in flight
|
|
68
|
+
let generation = self.clearNowPlayingInfoStorage()
|
|
67
69
|
|
|
68
70
|
// Gather new playing info
|
|
69
71
|
if let player = self.player,
|
|
70
72
|
let sourceDescription = player.source,
|
|
71
73
|
let metadata = sourceDescription.metadata {
|
|
72
74
|
let artWorkUrlString = self.getArtWorkUrlStringFromSourceDescription(sourceDescription)
|
|
73
|
-
self.nowPlayingInfo = [String : Any]()
|
|
74
75
|
self.updateTitle(metadata.title)
|
|
75
|
-
self.
|
|
76
|
+
self.updateSubtitleOrArtist(subtitle: metadata.metadataKeys?["subtitle"] as? String,
|
|
77
|
+
artist: metadata.metadataKeys?["artist"] as? String)
|
|
76
78
|
self.updateAlbum(metadata.metadataKeys?["album"] as? String)
|
|
77
|
-
self.updateSubtitle(metadata.metadataKeys?["subtitle"] as? String)
|
|
78
79
|
self.updateDuration(player.duration)
|
|
79
80
|
self.updateMediaType() // video
|
|
80
81
|
self.updatePlaybackRate(player.playbackRate)
|
|
81
82
|
self.updateServiceIdentifier(metadata.metadataKeys?["nowPlayingServiceIdentifier"] as? String)
|
|
82
83
|
self.updateContentIdentifier(metadata.metadataKeys?["nowPlayingContentIdentifier"] as? String)
|
|
83
84
|
self.updateCurrentTime(player.currentTime)
|
|
84
|
-
self.updateArtWork(artWorkUrlString) { [weak self] in
|
|
85
|
-
self?.
|
|
85
|
+
self.updateArtWork(artWorkUrlString, generation: generation) { [weak self] in
|
|
86
|
+
self?.processNowPlayingInfoToInfoCenter()
|
|
86
87
|
}
|
|
87
88
|
} else {
|
|
88
|
-
self.
|
|
89
|
+
self.clearNowPlayingInfoOnInfoCenter()
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
// MARK: - thread safe nowPlayingInfo access
|
|
94
|
+
// nowPlayingInfoStorage is touched both from the main thread (player event listeners,
|
|
95
|
+
// updateNowPlayingInfo, destroy) and from the URLSession delegate queue (artwork fetch
|
|
96
|
+
// completion). All access is serialized through nowPlayingQueue to avoid corrupting
|
|
97
|
+
// the dictionary storage.
|
|
98
|
+
//
|
|
99
|
+
// nowPlayingInfoGeneration identifies the source the storage is currently describing.
|
|
100
|
+
// It is bumped on every clear, so an artwork fetch that completes after a source change
|
|
101
|
+
// (or after the info was cleared) can detect that it is stale and skip both its write
|
|
102
|
+
// and the publication to the info center.
|
|
103
|
+
private func setNowPlayingInfoStorage(_ key: String, _ value: Any?) {
|
|
104
|
+
self.nowPlayingQueue.sync { self.nowPlayingInfoStorage[key] = value }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Writes only when the generation is still current; returns false when stale.
|
|
108
|
+
private func setNowPlayingInfoStorage(_ key: String, _ value: Any?, ifGeneration generation: Int) -> Bool {
|
|
109
|
+
self.nowPlayingQueue.sync {
|
|
110
|
+
guard generation == self.nowPlayingInfoGeneration else {
|
|
111
|
+
return false
|
|
112
|
+
}
|
|
113
|
+
self.nowPlayingInfoStorage[key] = value
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private func isCurrentNowPlayingInfoGeneration(_ generation: Int) -> Bool {
|
|
119
|
+
self.nowPlayingQueue.sync { generation == self.nowPlayingInfoGeneration }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
private func getNowPlayingInfoStorage() -> [String : Any] {
|
|
123
|
+
self.nowPlayingQueue.sync { self.nowPlayingInfoStorage }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@discardableResult
|
|
127
|
+
private func clearNowPlayingInfoStorage() -> Int {
|
|
128
|
+
self.nowPlayingQueue.sync {
|
|
129
|
+
self.nowPlayingInfoStorage = [:]
|
|
130
|
+
self.nowPlayingInfoGeneration += 1
|
|
131
|
+
return self.nowPlayingInfoGeneration
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private func processNowPlayingInfoToInfoCenter() {
|
|
136
|
+
let nowPlayingInfo = self.getNowPlayingInfoStorage()
|
|
94
137
|
if !nowPlayingInfo.isEmpty {
|
|
95
138
|
Task { @MainActor in
|
|
96
139
|
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
|
|
@@ -101,11 +144,11 @@ class THEOplayerRCTNowPlayingManager {
|
|
|
101
144
|
}
|
|
102
145
|
}
|
|
103
146
|
} else {
|
|
104
|
-
self.
|
|
147
|
+
self.clearNowPlayingInfoOnInfoCenter()
|
|
105
148
|
}
|
|
106
149
|
}
|
|
107
150
|
|
|
108
|
-
private func
|
|
151
|
+
private func clearNowPlayingInfoOnInfoCenter() {
|
|
109
152
|
Task { @MainActor in
|
|
110
153
|
MPNowPlayingInfoCenter.default().nowPlayingInfo = nil
|
|
111
154
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] clearing nowPlayingInfo (to nil) on infoCenter.") }
|
|
@@ -130,62 +173,70 @@ class THEOplayerRCTNowPlayingManager {
|
|
|
130
173
|
|
|
131
174
|
private func updateTitle(_ metadataTitle: String?) {
|
|
132
175
|
if let title = metadataTitle {
|
|
133
|
-
self.
|
|
176
|
+
self.setNowPlayingInfoStorage(MPMediaItemPropertyTitle, title)
|
|
134
177
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] title [\(title)] stored in nowPlayingInfo.") }
|
|
135
178
|
}
|
|
136
179
|
}
|
|
137
180
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
181
|
+
// MPMediaItemPropertyArtist holds the secondary line shown below the title. An audio
|
|
182
|
+
// stream typically describes it through an artist, while a video stream has no artist but
|
|
183
|
+
// can provide a subtitle (e.g. title "My Series" with subtitle "ep.8: My Episode Title").
|
|
184
|
+
// Only one of both can be displayed, so the subtitle takes precedence when both are set.
|
|
185
|
+
private func updateSubtitleOrArtist(subtitle metadataSubtitle: String?, artist metadataArtist: String?) {
|
|
186
|
+
if let subtitleOrArtist = metadataSubtitle ?? metadataArtist {
|
|
187
|
+
self.setNowPlayingInfoStorage(MPMediaItemPropertyArtist, subtitleOrArtist)
|
|
188
|
+
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] subtitle/artist [\(subtitleOrArtist)] stored in nowPlayingInfo.") }
|
|
142
189
|
}
|
|
143
190
|
}
|
|
144
191
|
|
|
145
192
|
private func updateAlbum(_ metadataAlbum: String?) {
|
|
146
193
|
if let album = metadataAlbum {
|
|
147
|
-
self.
|
|
194
|
+
self.setNowPlayingInfoStorage(MPMediaItemPropertyAlbumTitle, album)
|
|
148
195
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] album [\(album)] stored in nowPlayingInfo.") }
|
|
149
196
|
}
|
|
150
197
|
}
|
|
151
198
|
|
|
152
|
-
private func updateSubtitle(_ metadataSubtitle: String?) {
|
|
153
|
-
if let subtitle = metadataSubtitle {
|
|
154
|
-
self.nowPlayingInfo[MPMediaItemPropertyArtist] = subtitle
|
|
155
|
-
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] subtitle [\(subtitle)] stored in nowPlayingInfo.") }
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
199
|
private func updateServiceIdentifier(_ serviceId: String?) {
|
|
160
200
|
if let serviceId = serviceId {
|
|
161
|
-
self.
|
|
201
|
+
self.setNowPlayingInfoStorage(MPNowPlayingInfoPropertyServiceIdentifier, serviceId)
|
|
162
202
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] serviceId [\(serviceId)] stored in nowPlayingInfo.") }
|
|
163
203
|
}
|
|
164
204
|
}
|
|
165
205
|
|
|
166
206
|
private func updateContentIdentifier(_ contentId: String?) {
|
|
167
207
|
if let contentId = contentId {
|
|
168
|
-
self.
|
|
208
|
+
self.setNowPlayingInfoStorage(MPNowPlayingInfoPropertyExternalContentIdentifier, contentId)
|
|
169
209
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] contentId [\(contentId)] stored in nowPlayingInfo.") }
|
|
170
210
|
}
|
|
171
211
|
}
|
|
172
212
|
|
|
173
213
|
private func updateMediaType() {
|
|
174
|
-
self.
|
|
214
|
+
self.setNowPlayingInfoStorage(MPNowPlayingInfoPropertyMediaType, NSNumber(value: 2))
|
|
175
215
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] mediaType [hardcoded 2, for video] stored in nowPlayingInfo.") }
|
|
176
216
|
}
|
|
177
217
|
|
|
178
|
-
private func updateArtWork(_ urlString: String?, completion: (() -> Void)?) {
|
|
218
|
+
private func updateArtWork(_ urlString: String?, generation: Int, completion: (() -> Void)?) {
|
|
179
219
|
if let artUrlString = urlString,
|
|
180
220
|
let artUrl = URL(string: artUrlString) {
|
|
181
221
|
let dataTask = URLSession.shared.dataTask(with: artUrl) { [weak self] (data, _, _) in
|
|
222
|
+
guard let welf = self else {
|
|
223
|
+
return
|
|
224
|
+
}
|
|
182
225
|
if let displayIconData = data,
|
|
183
226
|
let displayIcon = UIImage(data: displayIconData) {
|
|
184
|
-
|
|
227
|
+
let artWork = MPMediaItemArtwork(boundsSize: displayIcon.size) { size in
|
|
185
228
|
return displayIcon
|
|
186
229
|
}
|
|
230
|
+
guard welf.setNowPlayingInfoStorage(MPMediaItemPropertyArtwork, artWork, ifGeneration: generation) else {
|
|
231
|
+
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] Artwork arrived for an outdated source, discarding it.") }
|
|
232
|
+
return
|
|
233
|
+
}
|
|
187
234
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] Artwork stored in nowPlayingInfo.") }
|
|
188
235
|
} else {
|
|
236
|
+
guard welf.isCurrentNowPlayingInfoGeneration(generation) else {
|
|
237
|
+
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] Artwork failed for an outdated source, discarding it.") }
|
|
238
|
+
return
|
|
239
|
+
}
|
|
189
240
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] Failed to store artwork in nowPlayingInfo.") }
|
|
190
241
|
}
|
|
191
242
|
completion?()
|
|
@@ -197,22 +248,22 @@ class THEOplayerRCTNowPlayingManager {
|
|
|
197
248
|
}
|
|
198
249
|
|
|
199
250
|
private func updatePlaybackRate(_ playerPlaybackRate: Double) {
|
|
200
|
-
self.
|
|
251
|
+
self.setNowPlayingInfoStorage(MPNowPlayingInfoPropertyPlaybackRate, NSNumber(value: playerPlaybackRate))
|
|
201
252
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] playbackrate [\(playerPlaybackRate)] stored in nowPlayingInfo.") }
|
|
202
253
|
}
|
|
203
254
|
|
|
204
255
|
private func updateCurrentTime(_ currentTime: Double) {
|
|
205
|
-
self.
|
|
256
|
+
self.setNowPlayingInfoStorage(MPNowPlayingInfoPropertyElapsedPlaybackTime, NSNumber(value: currentTime))
|
|
206
257
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] currentTime [\(currentTime)] stored in nowPlayingInfo.") }
|
|
207
258
|
}
|
|
208
259
|
|
|
209
260
|
private func updateDuration(_ duration: Double?) {
|
|
210
261
|
if let duration = duration {
|
|
211
262
|
let isLiveStream = duration.isInfinite
|
|
212
|
-
self.
|
|
263
|
+
self.setNowPlayingInfoStorage(MPNowPlayingInfoPropertyIsLiveStream, isLiveStream)
|
|
213
264
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] isLiveStream [\(isLiveStream)] stored in nowPlayingInfo.") }
|
|
214
265
|
if !isLiveStream {
|
|
215
|
-
self.
|
|
266
|
+
self.setNowPlayingInfoStorage(MPMediaItemPropertyPlaybackDuration, NSNumber(value: duration))
|
|
216
267
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO] duration [\(duration)] stored in nowPlayingInfo.") }
|
|
217
268
|
}
|
|
218
269
|
}
|
|
@@ -230,7 +281,7 @@ class THEOplayerRCTNowPlayingManager {
|
|
|
230
281
|
let wplayer = player,
|
|
231
282
|
let duration = wplayer.duration {
|
|
232
283
|
welf.updateDuration(duration)
|
|
233
|
-
welf.
|
|
284
|
+
welf.processNowPlayingInfoToInfoCenter()
|
|
234
285
|
}
|
|
235
286
|
}
|
|
236
287
|
|
|
@@ -241,7 +292,7 @@ class THEOplayerRCTNowPlayingManager {
|
|
|
241
292
|
let wplayer = player {
|
|
242
293
|
welf.updatePlaybackRate(wplayer.playbackRate)
|
|
243
294
|
welf.updateCurrentTime(wplayer.currentTime)
|
|
244
|
-
welf.
|
|
295
|
+
welf.processNowPlayingInfoToInfoCenter()
|
|
245
296
|
}
|
|
246
297
|
}
|
|
247
298
|
|
|
@@ -252,7 +303,7 @@ class THEOplayerRCTNowPlayingManager {
|
|
|
252
303
|
let wplayer = player {
|
|
253
304
|
welf.updatePlaybackRate(0)
|
|
254
305
|
welf.updateCurrentTime(wplayer.currentTime)
|
|
255
|
-
welf.
|
|
306
|
+
welf.processNowPlayingInfoToInfoCenter()
|
|
256
307
|
}
|
|
257
308
|
}
|
|
258
309
|
|
|
@@ -264,7 +315,7 @@ class THEOplayerRCTNowPlayingManager {
|
|
|
264
315
|
let wplayer = player {
|
|
265
316
|
welf.updatePlaybackRate(wplayer.playbackRate)
|
|
266
317
|
welf.updateCurrentTime(wplayer.currentTime)
|
|
267
|
-
welf.
|
|
318
|
+
welf.processNowPlayingInfoToInfoCenter()
|
|
268
319
|
}
|
|
269
320
|
}
|
|
270
321
|
|
|
@@ -275,14 +326,14 @@ class THEOplayerRCTNowPlayingManager {
|
|
|
275
326
|
let wplayer = player {
|
|
276
327
|
welf.updatePlaybackRate(wplayer.playbackRate)
|
|
277
328
|
welf.updateCurrentTime(wplayer.currentTime)
|
|
278
|
-
welf.
|
|
329
|
+
welf.processNowPlayingInfoToInfoCenter()
|
|
279
330
|
}
|
|
280
331
|
}
|
|
281
332
|
|
|
282
333
|
// SOURCE_CHANGE
|
|
283
334
|
self.sourceChangeListener = player.addEventListener(type: PlayerEventTypes.SOURCE_CHANGE) { [weak self] event in
|
|
284
335
|
if DEBUG_NOWINFO { PrintUtils.printLog(logText: "[NATIVE][NOWPLAYINGINFO-EVENT] SOURCE_CHANGE \(event.source == nil ? "to nil" : "")") }
|
|
285
|
-
self?.
|
|
336
|
+
self?.updateNowPlayingInfo()
|
|
286
337
|
}
|
|
287
338
|
}
|
|
288
339
|
|
|
@@ -9,6 +9,10 @@ import Foundation
|
|
|
9
9
|
import UIKit
|
|
10
10
|
import THEOplayerSDK
|
|
11
11
|
|
|
12
|
+
#if canImport(THEOplayerConnectorSideloadedSubtitle)
|
|
13
|
+
import THEOplayerConnectorSideloadedSubtitle
|
|
14
|
+
#endif
|
|
15
|
+
|
|
12
16
|
let CACHE_EVENT_PROP_STATUS: String = "status"
|
|
13
17
|
let CACHE_EVENT_PROP_PROGRESS: String = "progress"
|
|
14
18
|
let CACHE_EVENT_PROP_TASK: String = "task"
|
|
@@ -147,17 +151,25 @@ class THEOplayerRCTCacheAPI: RCTEventEmitter {
|
|
|
147
151
|
if DEBUG_CACHE_API { PrintUtils.printLog(logText: "[NATIVE] createTask triggered on Cache API.") }
|
|
148
152
|
let params = THEOplayerRCTCachingParametersBuilder.buildCachingParameters(params)
|
|
149
153
|
let (sourceDescription, _) = THEOplayerRCTSourceDescriptionBuilder.buildSourceDescription(src)
|
|
150
|
-
if let srcDescription = sourceDescription
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
154
|
+
if let srcDescription = sourceDescription {
|
|
155
|
+
#if canImport(THEOplayerConnectorSideloadedSubtitle)
|
|
156
|
+
let newTask = THEOplayer.cache.createTaskWithSubtitles(source: srcDescription, parameters: params)
|
|
157
|
+
#else
|
|
158
|
+
let newTask = THEOplayer.cache.createTask(source: srcDescription, parameters: params)
|
|
159
|
+
#endif
|
|
160
|
+
if let createdTask = newTask {
|
|
161
|
+
if DEBUG_CACHE_API { PrintUtils.printLog(logText: "[NATIVE] New cache task created with id \(createdTask.id)") }
|
|
162
|
+
resolve(THEOplayerRCTCacheAggregator.aggregateCacheTask(task: createdTask))
|
|
163
|
+
// emit onAddCachingTaskEvent
|
|
164
|
+
self.sendEvent(withName: "onAddCachingTaskEvent", body: [
|
|
165
|
+
CACHE_EVENT_PROP_TASK: THEOplayerRCTCacheAggregator.aggregateCacheTask(task: createdTask)
|
|
166
|
+
])
|
|
167
|
+
|
|
168
|
+
// attach the state and progress listeners to the new task
|
|
169
|
+
self.attachTaskListenersToTask(createdTask)
|
|
170
|
+
} else {
|
|
171
|
+
reject(ERROR_CODE_CREATE_CACHINGTASK_FAILED, ERROR_MESSAGE_CREATE_CACHINGTASK_FAILURE, nil)
|
|
172
|
+
}
|
|
161
173
|
} else {
|
|
162
174
|
reject(ERROR_CODE_CREATE_CACHINGTASK_FAILED, ERROR_MESSAGE_CREATE_CACHINGTASK_FAILURE, nil)
|
|
163
175
|
}
|