vdocipher-rn-bridge 2.0.1 → 2.1.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/VdoCastButton.tsx +22 -0
- package/VdoCastMiniController.tsx +21 -0
- package/VdoPlayerView.tsx +64 -0
- package/android/build.gradle +5 -3
- package/android/src/main/java/com/vdocipher/rnbridge/AudioFocusManager.java +7 -2
- package/android/src/main/java/com/vdocipher/rnbridge/PlayerViewRegistry.java +21 -0
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoCastButtonManagerImpl.java +40 -0
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoCastMiniControllerManagerImpl.java +12 -0
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerUIView.java +85 -59
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerUIViewManagerImpl.java +18 -0
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerView.java +450 -103
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerViewManagerImpl.java +30 -1
- package/android/src/main/java/com/vdocipher/rnbridge/TrackSelectionModuleImpl.java +13 -28
- package/android/src/main/java/com/vdocipher/rnbridge/Utils.java +36 -0
- package/android/src/main/java/com/vdocipher/rnbridge/VdoCastButtonView.java +59 -0
- package/android/src/main/java/com/vdocipher/rnbridge/VdoCastMiniControllerView.java +83 -0
- package/android/src/main/java/com/vdocipher/rnbridge/VdoDownloadModuleImpl.java +15 -3
- package/android/src/main/java/com/vdocipher/rnbridge/VdoEventEmitter.java +15 -2
- package/android/src/main/java/com/vdocipher/rnbridge/VdoPlayerModuleImpl.java +8 -10
- package/android/src/main/java/com/vdocipher/rnbridge/VdoPlayerSettingsModuleImpl.java +5 -0
- package/android/src/main/java/com/vdocipher/rnbridge/VdocipherRnBridgeModuleImpl.java +12 -0
- package/android/src/main/java/com/vdocipher/rnbridge/VdocipherRnBridgePackage.java +3 -1
- package/android/src/main/res/layout/vdo_cast_mini_controller.xml +9 -0
- package/android/src/main/res/values/vdo_cast_arrays.xml +9 -0
- package/android/src/newarch/java/com/vdocipher/rnbridge/ReactVdoCastButtonManager.java +44 -0
- package/android/src/newarch/java/com/vdocipher/rnbridge/ReactVdoCastMiniControllerManager.java +37 -0
- package/android/src/newarch/java/com/vdocipher/rnbridge/ReactVdoPlayerUIViewManager.java +12 -0
- package/android/src/newarch/java/com/vdocipher/rnbridge/ReactVdoPlayerViewManager.java +30 -0
- package/android/src/newarch/java/com/vdocipher/rnbridge/VdoPlayerModule.java +5 -0
- package/android/src/newarch/java/com/vdocipher/rnbridge/VdoPlayerSettingsModule.java +5 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/ReactVdoCastButtonManager.java +27 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/ReactVdoCastMiniControllerManager.java +19 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/ReactVdoPlayerUIViewManager.java +4 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/ReactVdoPlayerViewManager.java +13 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/VdoPlayerModule.java +5 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/VdoPlayerSettingsModule.java +5 -0
- package/downloads.ts +4 -1
- package/index.ts +4 -0
- package/ios/RCTVdoPlayerUIView.swift +38 -11
- package/ios/RCTVdoPlayerUIViewComponentView.mm +1 -0
- package/ios/RCTVdoPlayerView.swift +5 -2
- package/ios/RCTVdoPlayerViewComponentView.mm +1 -0
- package/ios/VdoCipherRNView.h +1 -0
- package/ios/VdoCipherRNView.swift +142 -19
- package/ios/VdoEventEmitter.swift +2 -0
- package/ios/VdoPlaybackProperties.h +1 -0
- package/ios/VdoPlaybackProperties.swift +5 -0
- package/ios/VdoPlayerCommandDispatch.h +4 -0
- package/ios/VdoPlayerSettings.swift +5 -0
- package/ios/VdocipherRnBridgeViewManager.mm +12 -0
- package/ios/VdocipherRnBridgeViewManager.swift +5 -1
- package/package.json +3 -1
- package/specs/NativeVdoPlayer.ts +1 -0
- package/specs/NativeVdoPlayerSettings.ts +2 -0
- package/specs/RCTVdoCastButtonNativeComponent.ts +11 -0
- package/specs/RCTVdoCastMiniControllerNativeComponent.ts +9 -0
- package/specs/RCTVdoPlayerUIViewNativeComponent.ts +13 -0
- package/specs/RCTVdoPlayerViewNativeComponent.ts +19 -0
- package/type.ts +51 -1
|
@@ -46,6 +46,10 @@ public class ReactVdoPlayerViewManager extends ViewGroupManager<ReactVdoPlayerVi
|
|
|
46
46
|
private static final int COMMAND_ENABLE_ADAPTIVE_VIDEO = 10;
|
|
47
47
|
private static final int COMMAND_SET_VIDEO_QUALITY = 11;
|
|
48
48
|
private static final int COMMAND_SET_CAPTION_LANGUAGE = 12;
|
|
49
|
+
private static final int COMMAND_STOP_CASTING = 13;
|
|
50
|
+
private static final int COMMAND_OPEN_CAST_CONTROLS = 14;
|
|
51
|
+
private static final int COMMAND_MUTE = 15;
|
|
52
|
+
private static final int COMMAND_UNMUTE = 16;
|
|
49
53
|
|
|
50
54
|
private final ViewManagerDelegate<ReactVdoPlayerView> mDelegate;
|
|
51
55
|
|
|
@@ -96,6 +100,10 @@ public class ReactVdoPlayerViewManager extends ViewGroupManager<ReactVdoPlayerVi
|
|
|
96
100
|
.put("enableAdaptiveVideo", COMMAND_ENABLE_ADAPTIVE_VIDEO)
|
|
97
101
|
.put("setVideoQuality", COMMAND_SET_VIDEO_QUALITY)
|
|
98
102
|
.put("setCaptionLanguage", COMMAND_SET_CAPTION_LANGUAGE)
|
|
103
|
+
.put("stopCasting", COMMAND_STOP_CASTING)
|
|
104
|
+
.put("openCastControls", COMMAND_OPEN_CAST_CONTROLS)
|
|
105
|
+
.put("mute", COMMAND_MUTE)
|
|
106
|
+
.put("unmute", COMMAND_UNMUTE)
|
|
99
107
|
.build();
|
|
100
108
|
}
|
|
101
109
|
|
|
@@ -131,6 +139,12 @@ public class ReactVdoPlayerViewManager extends ViewGroupManager<ReactVdoPlayerVi
|
|
|
131
139
|
reactVdoPlayerViewManagerImpl.setAutoPlay(vdoPlayerView, autoPlay);
|
|
132
140
|
}
|
|
133
141
|
|
|
142
|
+
@Override
|
|
143
|
+
@ReactProp(name = "chromecastEnabled")
|
|
144
|
+
public void setChromecastEnabled(ReactVdoPlayerView vdoPlayerView, boolean chromecastEnabled) {
|
|
145
|
+
reactVdoPlayerViewManagerImpl.setChromecastEnabled(vdoPlayerView, chromecastEnabled);
|
|
146
|
+
}
|
|
147
|
+
|
|
134
148
|
public void play(ReactVdoPlayerView view) {
|
|
135
149
|
reactVdoPlayerViewManagerImpl.receiveCommand(view, "play", null);
|
|
136
150
|
}
|
|
@@ -171,4 +185,20 @@ public class ReactVdoPlayerViewManager extends ViewGroupManager<ReactVdoPlayerVi
|
|
|
171
185
|
reactVdoPlayerViewManagerImpl.receiveCommand(view, "disableCaptions", null);
|
|
172
186
|
}
|
|
173
187
|
|
|
188
|
+
public void stopCasting(ReactVdoPlayerView view) {
|
|
189
|
+
reactVdoPlayerViewManagerImpl.receiveCommand(view, "stopCasting", null);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public void openCastControls(ReactVdoPlayerView view) {
|
|
193
|
+
reactVdoPlayerViewManagerImpl.receiveCommand(view, "openCastControls", null);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public void mute(ReactVdoPlayerView view) {
|
|
197
|
+
reactVdoPlayerViewManagerImpl.receiveCommand(view, "mute", null);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
public void unmute(ReactVdoPlayerView view) {
|
|
201
|
+
reactVdoPlayerViewManagerImpl.receiveCommand(view, "unmute", null);
|
|
202
|
+
}
|
|
203
|
+
|
|
174
204
|
}
|
|
@@ -26,4 +26,9 @@ public class VdoPlayerModule extends NativeVdoPlayerSpec {
|
|
|
26
26
|
vdoPlayerModuleImpl.getPlaybackPropertiesV2(callback);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
@Override
|
|
30
|
+
public void isMuted(com.facebook.react.bridge.Callback callback) {
|
|
31
|
+
vdoPlayerModuleImpl.isMuted(callback);
|
|
32
|
+
}
|
|
33
|
+
|
|
29
34
|
}
|
|
@@ -39,4 +39,9 @@ public class VdoPlayerSettingsModule extends NativeVdoPlayerSettingsSpec {
|
|
|
39
39
|
vdoPlayerSettingsModuleImpl.applySettings(playerSettings);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
@Override()
|
|
43
|
+
public void setPictureInPictureActionsEnabled(boolean enabled) {
|
|
44
|
+
vdoPlayerSettingsModuleImpl.setPictureInPictureActionsEnabled(enabled);
|
|
45
|
+
}
|
|
46
|
+
|
|
42
47
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package com.vdocipher.rnbridge;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.uimanager.SimpleViewManager;
|
|
6
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
7
|
+
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
8
|
+
|
|
9
|
+
public class ReactVdoCastButtonManager extends SimpleViewManager<VdoCastButtonView> {
|
|
10
|
+
|
|
11
|
+
private final ReactVdoCastButtonManagerImpl impl = new ReactVdoCastButtonManagerImpl();
|
|
12
|
+
|
|
13
|
+
@Override
|
|
14
|
+
public String getName() {
|
|
15
|
+
return ReactVdoCastButtonManagerImpl.REACT_CLASS;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Override
|
|
19
|
+
public VdoCastButtonView createViewInstance(ThemedReactContext context) {
|
|
20
|
+
return impl.createViewInstance(context);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@ReactProp(name = "tint", customType = "Color")
|
|
24
|
+
public void setTint(VdoCastButtonView view, @Nullable Integer tint) {
|
|
25
|
+
impl.setTint(view, tint);
|
|
26
|
+
}
|
|
27
|
+
}
|
package/android/src/oldarch/java/com/vdocipher/rnbridge/ReactVdoCastMiniControllerManager.java
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.vdocipher.rnbridge;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.uimanager.SimpleViewManager;
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
5
|
+
|
|
6
|
+
public class ReactVdoCastMiniControllerManager extends SimpleViewManager<VdoCastMiniControllerView> {
|
|
7
|
+
|
|
8
|
+
private final ReactVdoCastMiniControllerManagerImpl impl = new ReactVdoCastMiniControllerManagerImpl();
|
|
9
|
+
|
|
10
|
+
@Override
|
|
11
|
+
public String getName() {
|
|
12
|
+
return ReactVdoCastMiniControllerManagerImpl.REACT_CLASS;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Override
|
|
16
|
+
public VdoCastMiniControllerView createViewInstance(ThemedReactContext context) {
|
|
17
|
+
return impl.createViewInstance(context);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -38,6 +38,8 @@ public class ReactVdoPlayerUIViewManager extends ViewGroupManager<ReactVdoPlayer
|
|
|
38
38
|
private static final int COMMAND_ENABLE_ADAPTIVE_VIDEO = 10;
|
|
39
39
|
private static final int COMMAND_SET_VIDEO_QUALITY = 11;
|
|
40
40
|
private static final int COMMAND_SET_CAPTION_LANGUAGE = 12;
|
|
41
|
+
private static final int COMMAND_MUTE = 13;
|
|
42
|
+
private static final int COMMAND_UNMUTE = 14;
|
|
41
43
|
|
|
42
44
|
public ReactVdoPlayerUIViewManager(ReactApplicationContext context, PlayerViewRegistry registry) {
|
|
43
45
|
reactVdoPlayerUIViewManagerImpl = new ReactVdoPlayerUIViewManagerImpl(registry);
|
|
@@ -79,6 +81,8 @@ public class ReactVdoPlayerUIViewManager extends ViewGroupManager<ReactVdoPlayer
|
|
|
79
81
|
.put("enableAdaptiveVideo", COMMAND_ENABLE_ADAPTIVE_VIDEO)
|
|
80
82
|
.put("setVideoQuality", COMMAND_SET_VIDEO_QUALITY)
|
|
81
83
|
.put("setCaptionLanguage", COMMAND_SET_CAPTION_LANGUAGE)
|
|
84
|
+
.put("mute", COMMAND_MUTE)
|
|
85
|
+
.put("unmute", COMMAND_UNMUTE)
|
|
82
86
|
.build();
|
|
83
87
|
}
|
|
84
88
|
|
|
@@ -35,6 +35,10 @@ public class ReactVdoPlayerViewManager extends ViewGroupManager<ReactVdoPlayerVi
|
|
|
35
35
|
private static final int COMMAND_ENABLE_ADAPTIVE_VIDEO = 10;
|
|
36
36
|
private static final int COMMAND_SET_VIDEO_QUALITY = 11;
|
|
37
37
|
private static final int COMMAND_SET_CAPTION_LANGUAGE = 12;
|
|
38
|
+
private static final int COMMAND_STOP_CASTING = 13;
|
|
39
|
+
private static final int COMMAND_OPEN_CAST_CONTROLS = 14;
|
|
40
|
+
private static final int COMMAND_MUTE = 15;
|
|
41
|
+
private static final int COMMAND_UNMUTE = 16;
|
|
38
42
|
|
|
39
43
|
public ReactVdoPlayerViewManager(ReactApplicationContext context, PlayerViewRegistry registry) {
|
|
40
44
|
reactVdoPlayerViewManagerImpl = new ReactVdoPlayerViewManagerImpl(registry);
|
|
@@ -74,6 +78,10 @@ public class ReactVdoPlayerViewManager extends ViewGroupManager<ReactVdoPlayerVi
|
|
|
74
78
|
.put("enableAdaptiveVideo", COMMAND_ENABLE_ADAPTIVE_VIDEO)
|
|
75
79
|
.put("setVideoQuality", COMMAND_SET_VIDEO_QUALITY)
|
|
76
80
|
.put("setCaptionLanguage", COMMAND_SET_CAPTION_LANGUAGE)
|
|
81
|
+
.put("stopCasting", COMMAND_STOP_CASTING)
|
|
82
|
+
.put("openCastControls", COMMAND_OPEN_CAST_CONTROLS)
|
|
83
|
+
.put("mute", COMMAND_MUTE)
|
|
84
|
+
.put("unmute", COMMAND_UNMUTE)
|
|
77
85
|
.build();
|
|
78
86
|
}
|
|
79
87
|
|
|
@@ -106,4 +114,9 @@ public class ReactVdoPlayerViewManager extends ViewGroupManager<ReactVdoPlayerVi
|
|
|
106
114
|
reactVdoPlayerViewManagerImpl.setAutoPlay(vdoPlayerView, autoPlay);
|
|
107
115
|
}
|
|
108
116
|
|
|
117
|
+
@ReactProp(name = "chromecastEnabled", defaultBoolean = false)
|
|
118
|
+
public void setChromecastEnabled(ReactVdoPlayerView vdoPlayerView, boolean chromecastEnabled) {
|
|
119
|
+
reactVdoPlayerViewManagerImpl.setChromecastEnabled(vdoPlayerView, chromecastEnabled);
|
|
120
|
+
}
|
|
121
|
+
|
|
109
122
|
}
|
|
@@ -26,4 +26,9 @@ public class VdoPlayerModule extends ReactContextBaseJavaModule {
|
|
|
26
26
|
vdoPlayerModuleImpl.getPlaybackPropertiesV2(callback);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
@ReactMethod()
|
|
30
|
+
public void isMuted(com.facebook.react.bridge.Callback callback) {
|
|
31
|
+
vdoPlayerModuleImpl.isMuted(callback);
|
|
32
|
+
}
|
|
33
|
+
|
|
29
34
|
}
|
|
@@ -37,4 +37,9 @@ public class VdoPlayerSettingsModule extends ReactContextBaseJavaModule {
|
|
|
37
37
|
vdoPlayerSettingsModuleImpl.applySettings(playerSettings);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
@ReactMethod()
|
|
41
|
+
public void setPictureInPictureActionsEnabled(boolean enabled) {
|
|
42
|
+
vdoPlayerSettingsModuleImpl.setPictureInPictureActionsEnabled(enabled);
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
}
|
package/downloads.ts
CHANGED
|
@@ -35,7 +35,10 @@ const getEnqueueFn = (nativeId: string) => (downloadOptions: VdoTypes.EnqueueSel
|
|
|
35
35
|
|
|
36
36
|
return new Promise<void>(function(resolve, reject) {
|
|
37
37
|
const requestOptions = {
|
|
38
|
-
selections: downloadOptions.selections
|
|
38
|
+
selections: downloadOptions.selections,
|
|
39
|
+
notificationTitle: downloadOptions.notificationTitle,
|
|
40
|
+
notificationDescription: downloadOptions.notificationDescription,
|
|
41
|
+
disableAnalytics: downloadOptions.disableAnalytics ?? false
|
|
39
42
|
};
|
|
40
43
|
|
|
41
44
|
VdoDownload.enqueueDownload(
|
package/index.ts
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { NativeModules, Platform } from 'react-native';
|
|
13
13
|
import VdoPlayerView from './VdoPlayerView';
|
|
14
|
+
import VdoCastButton from './VdoCastButton';
|
|
15
|
+
import VdoCastMiniController from './VdoCastMiniController';
|
|
14
16
|
import VdoDownload from './downloads';
|
|
15
17
|
import { EmbedInfo } from './type';
|
|
16
18
|
|
|
@@ -26,6 +28,8 @@
|
|
|
26
28
|
export {
|
|
27
29
|
startVideoScreen,
|
|
28
30
|
VdoPlayerView,
|
|
31
|
+
VdoCastButton,
|
|
32
|
+
VdoCastMiniController,
|
|
29
33
|
VdoDownload
|
|
30
34
|
}
|
|
31
35
|
|
|
@@ -14,8 +14,12 @@ import VdoFramework
|
|
|
14
14
|
class RCTVdoPlayerUIView: VdoCipherRNView {
|
|
15
15
|
|
|
16
16
|
var activityView: UIActivityIndicatorView?
|
|
17
|
-
|
|
17
|
+
// True once this view has hosted the shared surface, so we only reload on
|
|
18
|
+
// reappearance (not the initial mount, which loads on its own).
|
|
19
|
+
private var hasAttachedSurface = false
|
|
20
|
+
|
|
18
21
|
override func setEmbedInfo(_ embedInfo: [String: Any]) {
|
|
22
|
+
retainedEmbedInfo = embedInfo
|
|
19
23
|
guard shouldApplyEmbedInfo(embedInfo) else { return }
|
|
20
24
|
super.setEmbedInfo(embedInfo)
|
|
21
25
|
|
|
@@ -35,19 +39,42 @@ class RCTVdoPlayerUIView: VdoCipherRNView {
|
|
|
35
39
|
|
|
36
40
|
override func setUpPlayer(_ player: AVPlayer) {
|
|
37
41
|
let playerViewController = VdoCipher.getVdoPlayerViewController()
|
|
38
|
-
playerViewController.view.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
self.
|
|
43
|
-
|
|
42
|
+
let host = playerViewController.view.superview
|
|
43
|
+
// Attach unless already ours, or fullscreen (host is a window/SDK view). Another
|
|
44
|
+
// RCTVdoPlayerUIView host means a different screen owns it -> steal.
|
|
45
|
+
if host == nil || (host is RCTVdoPlayerUIView && host !== self) {
|
|
46
|
+
guard let reactVC = self.reactViewController() else {
|
|
47
|
+
let errorDescription = ErrorDescription(errorCode: 3100, errorMsg: "Error: 3100 Failed to Load reactViewController. Please try again.", httpStatusCode: -1)
|
|
48
|
+
self.sendErrorEventWithDescription(errorDescription)
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
// Detach the view too before addChild, else it throws
|
|
52
|
+
// UIViewControllerHierarchyInconsistency (view still owned by the old screen).
|
|
53
|
+
playerViewController.willMove(toParent: nil)
|
|
54
|
+
playerViewController.view.removeFromSuperview()
|
|
55
|
+
playerViewController.removeFromParent()
|
|
56
|
+
|
|
57
|
+
playerViewController.view.frame = self.bounds
|
|
58
|
+
playerViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
59
|
+
reactVC.addChild(playerViewController)
|
|
60
|
+
self.addSubview(playerViewController.view)
|
|
61
|
+
playerViewController.didMove(toParent: reactVC)
|
|
62
|
+
playerViewController.view.isHidden = true
|
|
63
|
+
hasAttachedSurface = true
|
|
44
64
|
}
|
|
45
|
-
reactVC.addChild(playerViewController)
|
|
46
|
-
self.addSubview(playerViewController.view)
|
|
47
|
-
playerViewController.didMove(toParent: reactVC)
|
|
48
|
-
playerViewController.view.isHidden = true
|
|
49
65
|
super.setUpPlayer(player)
|
|
50
66
|
}
|
|
67
|
+
|
|
68
|
+
override func setScreenFocused(_ val: Bool) {
|
|
69
|
+
// On refocus, if another screen stole the shared surface, reload to re-acquire it
|
|
70
|
+
// (New Arch preserves the view, so playback won't otherwise restart on return).
|
|
71
|
+
if val, hasAttachedSurface, retainedEmbedInfo != nil,
|
|
72
|
+
VdoCipher.getVdoPlayerViewController().view.superview !== self {
|
|
73
|
+
reloadRetainedEmbedInfo()
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
super.setScreenFocused(val)
|
|
77
|
+
}
|
|
51
78
|
|
|
52
79
|
override func playerReadyToPlay() {
|
|
53
80
|
self.hideActivityIndicator()
|
|
@@ -85,6 +85,7 @@ using namespace facebook::react;
|
|
|
85
85
|
addOptInt(@"clipEndInMs", ei.clipEndInMs);
|
|
86
86
|
addOptBool(@"clipped", ei.clipped);
|
|
87
87
|
addOptStr(@"clipMarkerColor", ei.clipMarkerColor);
|
|
88
|
+
addOptBool(@"startMuted", ei.startMuted);
|
|
88
89
|
|
|
89
90
|
// Dedup of unchanged embedInfo is handled natively in VdoCipherRNView.setEmbedInfo
|
|
90
91
|
// (covers both arches), so just forward it here.
|
|
@@ -12,9 +12,12 @@ import AVKit
|
|
|
12
12
|
|
|
13
13
|
@objc(RCTVdoPlayerView)
|
|
14
14
|
class RCTVdoPlayerView: VdoCipherRNView {
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
var playerLayer: AVPlayerLayer?
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
// Raw AVPlayerLayer + custom RN UI: owns the system media controls itself.
|
|
19
|
+
override var usesCustomUI: Bool { return true }
|
|
20
|
+
|
|
18
21
|
override func setEmbedInfo(_ embedInfo: [String: Any]) {
|
|
19
22
|
guard shouldApplyEmbedInfo(embedInfo) else { return }
|
|
20
23
|
super.setEmbedInfo(embedInfo)
|
|
@@ -85,6 +85,7 @@ using namespace facebook::react;
|
|
|
85
85
|
addOptInt(@"clipEndInMs", ei.clipEndInMs);
|
|
86
86
|
addOptBool(@"clipped", ei.clipped);
|
|
87
87
|
addOptStr(@"clipMarkerColor", ei.clipMarkerColor);
|
|
88
|
+
addOptBool(@"startMuted", ei.startMuted);
|
|
88
89
|
|
|
89
90
|
// Dedup of unchanged embedInfo is handled natively in VdoCipherRNView.setEmbedInfo
|
|
90
91
|
// (covers both arches), so just forward it here.
|
package/ios/VdoCipherRNView.h
CHANGED
|
@@ -8,12 +8,16 @@
|
|
|
8
8
|
import Foundation
|
|
9
9
|
import AVKit
|
|
10
10
|
import VdoFramework
|
|
11
|
+
import MediaPlayer
|
|
11
12
|
|
|
12
13
|
class VdoCipherRNView: UIView {
|
|
13
|
-
|
|
14
|
+
|
|
14
15
|
@objc var player: AVPlayer?
|
|
15
16
|
@objc var asset: VdoAsset?
|
|
16
|
-
|
|
17
|
+
|
|
18
|
+
/// Custom-UI subclasses own the system media controls themselves.
|
|
19
|
+
var usesCustomUI: Bool { return false }
|
|
20
|
+
|
|
17
21
|
private var preferredCaptionsLanguage: String?
|
|
18
22
|
private var playWhenReady: Bool = true
|
|
19
23
|
private var progressTimer: Timer?
|
|
@@ -22,6 +26,14 @@ class VdoCipherRNView: UIView {
|
|
|
22
26
|
private var playbackType: PlaybackType = .streaming
|
|
23
27
|
private var resumeTime: CMTime?
|
|
24
28
|
private var lastEmbedInfo: [String: Any]?
|
|
29
|
+
// Last embedInfo applied, kept across cleanup() so the view can reload itself when
|
|
30
|
+
// it reappears (New Arch preserves the view instead of recreating it).
|
|
31
|
+
var retainedEmbedInfo: [String: Any]?
|
|
32
|
+
// startMuted of new embedInfo, then the last mute/unmute; applied to each attached AVPlayer.
|
|
33
|
+
private var mutedState = false
|
|
34
|
+
private var mutedForEmbedInfo: [String: Any]?
|
|
35
|
+
// The view that loaded media last; isMuted() reports on it.
|
|
36
|
+
private static weak var activeView: VdoCipherRNView?
|
|
25
37
|
|
|
26
38
|
private var playerItemBufferEmptyObserver: NSKeyValueObservation?
|
|
27
39
|
private var playerItemBufferKeepUpObserver: NSKeyValueObservation?
|
|
@@ -66,6 +78,7 @@ class VdoCipherRNView: UIView {
|
|
|
66
78
|
|
|
67
79
|
@objc func cleanup() {
|
|
68
80
|
player?.pause()
|
|
81
|
+
self.teardownRemoteCommandCenter()
|
|
69
82
|
self.removeObservers()
|
|
70
83
|
player?.replaceCurrentItem(with: nil)
|
|
71
84
|
player = nil
|
|
@@ -79,6 +92,24 @@ class VdoCipherRNView: UIView {
|
|
|
79
92
|
playerState = .unknown
|
|
80
93
|
isLoaded = false
|
|
81
94
|
lastEmbedInfo = nil
|
|
95
|
+
// A recycled view must start fresh; reloadRetainedEmbedInfo restores these itself.
|
|
96
|
+
mutedState = false
|
|
97
|
+
mutedForEmbedInfo = nil
|
|
98
|
+
if VdoCipherRNView.activeView === self {
|
|
99
|
+
VdoCipherRNView.activeView = nil
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// Reload the last embedInfo when the view reappears. The SDK conserves playback
|
|
104
|
+
/// state (quality, resume, captions) across the reload.
|
|
105
|
+
func reloadRetainedEmbedInfo() {
|
|
106
|
+
guard let info = retainedEmbedInfo else { return }
|
|
107
|
+
let keptMutedState = mutedState
|
|
108
|
+
let keptMutedForEmbedInfo = mutedForEmbedInfo
|
|
109
|
+
cleanup()
|
|
110
|
+
mutedState = keptMutedState
|
|
111
|
+
mutedForEmbedInfo = keptMutedForEmbedInfo
|
|
112
|
+
setEmbedInfo(info)
|
|
82
113
|
}
|
|
83
114
|
|
|
84
115
|
func shouldApplyEmbedInfo(_ embedInfo: [String: Any]) -> Bool {
|
|
@@ -95,7 +126,13 @@ class VdoCipherRNView: UIView {
|
|
|
95
126
|
selector: #selector(videoDidEnd),
|
|
96
127
|
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
|
|
97
128
|
object: nil)
|
|
98
|
-
|
|
129
|
+
if usesCustomUI {
|
|
130
|
+
NotificationCenter.default.addObserver(self,
|
|
131
|
+
selector: #selector(handleEnterBackground),
|
|
132
|
+
name: UIApplication.didEnterBackgroundNotification,
|
|
133
|
+
object: nil)
|
|
134
|
+
}
|
|
135
|
+
|
|
99
136
|
playerItemBufferEmptyObserver = self.player?.currentItem?.observe(\AVPlayerItem.isPlaybackBufferEmpty, options: [.new]) { [weak self] (_, _) in
|
|
100
137
|
guard let self = self else { return }
|
|
101
138
|
if self.playbackType == .offline || self.playerState == .buffering {
|
|
@@ -157,7 +194,10 @@ class VdoCipherRNView: UIView {
|
|
|
157
194
|
NotificationCenter.default.removeObserver(self,
|
|
158
195
|
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
|
|
159
196
|
object: nil)
|
|
160
|
-
|
|
197
|
+
NotificationCenter.default.removeObserver(self,
|
|
198
|
+
name: UIApplication.didEnterBackgroundNotification,
|
|
199
|
+
object: nil)
|
|
200
|
+
|
|
161
201
|
playerItemBufferEmptyObserver?.invalidate()
|
|
162
202
|
playerItemBufferEmptyObserver = nil
|
|
163
203
|
|
|
@@ -170,7 +210,77 @@ class VdoCipherRNView: UIView {
|
|
|
170
210
|
progressTimer?.invalidate()
|
|
171
211
|
progressTimer = nil
|
|
172
212
|
}
|
|
173
|
-
|
|
213
|
+
|
|
214
|
+
@objc func handleEnterBackground() {
|
|
215
|
+
// Re-claim the command center once backgrounded, so our handlers replace the framework's.
|
|
216
|
+
setupRemoteCommandCenter()
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/// Installs play/pause/toggle handlers bound to self.player, replacing any
|
|
220
|
+
/// pre-existing targets (which may reference a deallocated controller).
|
|
221
|
+
private func setupRemoteCommandCenter() {
|
|
222
|
+
guard usesCustomUI else { return }
|
|
223
|
+
|
|
224
|
+
let commandCenter = MPRemoteCommandCenter.shared()
|
|
225
|
+
|
|
226
|
+
commandCenter.playCommand.removeTarget(nil)
|
|
227
|
+
commandCenter.pauseCommand.removeTarget(nil)
|
|
228
|
+
commandCenter.togglePlayPauseCommand.removeTarget(nil)
|
|
229
|
+
|
|
230
|
+
commandCenter.playCommand.isEnabled = true
|
|
231
|
+
commandCenter.pauseCommand.isEnabled = true
|
|
232
|
+
commandCenter.togglePlayPauseCommand.isEnabled = true
|
|
233
|
+
|
|
234
|
+
commandCenter.playCommand.addTarget { [weak self] _ in
|
|
235
|
+
guard let self = self, let player = self.player else { return .noSuchContent }
|
|
236
|
+
player.rate = self.targetPlaybackSpeed
|
|
237
|
+
self.playWhenReady = true
|
|
238
|
+
self.playerState = .ready
|
|
239
|
+
self.updateNowPlayingPlaybackInfo()
|
|
240
|
+
return .success
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
commandCenter.pauseCommand.addTarget { [weak self] _ in
|
|
244
|
+
guard let self = self, let player = self.player else { return .noSuchContent }
|
|
245
|
+
player.pause()
|
|
246
|
+
self.playWhenReady = false
|
|
247
|
+
self.playerState = .ready
|
|
248
|
+
self.updateNowPlayingPlaybackInfo()
|
|
249
|
+
return .success
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
commandCenter.togglePlayPauseCommand.addTarget { [weak self] _ in
|
|
253
|
+
guard let self = self, let player = self.player else { return .noSuchContent }
|
|
254
|
+
if player.rate == 0 {
|
|
255
|
+
player.rate = self.targetPlaybackSpeed
|
|
256
|
+
self.playWhenReady = true
|
|
257
|
+
} else {
|
|
258
|
+
player.pause()
|
|
259
|
+
self.playWhenReady = false
|
|
260
|
+
}
|
|
261
|
+
self.playerState = .ready
|
|
262
|
+
self.updateNowPlayingPlaybackInfo()
|
|
263
|
+
return .success
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/// Keeps the lock-screen playback state in sync after our command handlers run.
|
|
268
|
+
private func updateNowPlayingPlaybackInfo() {
|
|
269
|
+
guard let player = self.player else { return }
|
|
270
|
+
var info = MPNowPlayingInfoCenter.default().nowPlayingInfo ?? [String: Any]()
|
|
271
|
+
info[MPNowPlayingInfoPropertyElapsedPlaybackTime] = player.currentItem?.currentTime().seconds ?? 0
|
|
272
|
+
info[MPNowPlayingInfoPropertyPlaybackRate] = player.rate
|
|
273
|
+
MPNowPlayingInfoCenter.default().nowPlayingInfo = info
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private func teardownRemoteCommandCenter() {
|
|
277
|
+
guard usesCustomUI else { return }
|
|
278
|
+
let commandCenter = MPRemoteCommandCenter.shared()
|
|
279
|
+
commandCenter.playCommand.removeTarget(nil)
|
|
280
|
+
commandCenter.pauseCommand.removeTarget(nil)
|
|
281
|
+
commandCenter.togglePlayPauseCommand.removeTarget(nil)
|
|
282
|
+
}
|
|
283
|
+
|
|
174
284
|
func parseOfflineCredentials(fromInfo embedInfo: [String: Any]) {
|
|
175
285
|
guard let mediaId = embedInfo["mediaId"] as? String else {
|
|
176
286
|
let errorDescription = ErrorDescription(errorCode: 4101, errorMsg: "Error: 4101 Invalid video parameters. Please contact the app developer.", httpStatusCode: -1)
|
|
@@ -292,6 +402,10 @@ class VdoCipherRNView: UIView {
|
|
|
292
402
|
_ = self.setCaptionLanguage(lanCode: self.preferredCaptionsLanguage)
|
|
293
403
|
}
|
|
294
404
|
}
|
|
405
|
+
// Defer so our command handlers replace the framework's rather than precede them.
|
|
406
|
+
DispatchQueue.main.async { [weak self] in
|
|
407
|
+
self?.setupRemoteCommandCenter()
|
|
408
|
+
}
|
|
295
409
|
if let resumeTime = self.resumeTime {
|
|
296
410
|
player?.seek(to: resumeTime, completionHandler: { [weak self] _ in
|
|
297
411
|
self?.player?.rate = self?.playWhenReady == true ? self?.targetPlaybackSpeed ?? 1.0 : 0
|
|
@@ -306,6 +420,23 @@ class VdoCipherRNView: UIView {
|
|
|
306
420
|
}
|
|
307
421
|
|
|
308
422
|
@objc func setEmbedInfo(_ embedInfo: [String: Any]) {
|
|
423
|
+
// Equal embedInfo is the same media, which keeps its mute state.
|
|
424
|
+
let sameMedia = (mutedForEmbedInfo as NSDictionary?)?.isEqual(to: embedInfo) ?? false
|
|
425
|
+
if !sameMedia {
|
|
426
|
+
mutedForEmbedInfo = embedInfo
|
|
427
|
+
mutedState = embedInfo["startMuted"] as? Bool ?? false
|
|
428
|
+
}
|
|
429
|
+
player?.isMuted = mutedState
|
|
430
|
+
VdoCipherRNView.activeView = self
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
@objc func setMuted(_ muted: Bool) {
|
|
434
|
+
mutedState = muted
|
|
435
|
+
player?.isMuted = muted
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
static func currentMuteState() -> Bool {
|
|
439
|
+
return activeView?.mutedState ?? false
|
|
309
440
|
}
|
|
310
441
|
|
|
311
442
|
@objc func setResizeMode(_ resizeMode: String) {
|
|
@@ -322,18 +453,9 @@ class VdoCipherRNView: UIView {
|
|
|
322
453
|
if playerState != .ready {
|
|
323
454
|
VdoCipher.enableAutoPlay = self.playWhenReady
|
|
324
455
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
// Above Condition implies the playback was paused and play is triggered
|
|
330
|
-
// The condition is required since we need to keep the playbackSpeed in case user navigates to and fro this screen.
|
|
331
|
-
self.player?.rate = targetPlaybackSpeed
|
|
332
|
-
} else {
|
|
333
|
-
// Below on pause 'targetPlaybackSpeed' is set to 0 which implies when user navigates back to this screen playback shouldn't resume
|
|
334
|
-
self.targetPlaybackSpeed = 0
|
|
335
|
-
self.player?.rate = 0
|
|
336
|
-
}
|
|
456
|
+
// playWhenReady is the single source of truth for play/pause; targetPlaybackSpeed
|
|
457
|
+
// only holds the desired rate, so it survives a pause and restores on resume.
|
|
458
|
+
self.player?.rate = playWhenReady ? targetPlaybackSpeed : 0
|
|
337
459
|
}
|
|
338
460
|
|
|
339
461
|
@objc func setPlaybackSpeed(_ speed: Float) {
|
|
@@ -378,7 +500,7 @@ class VdoCipherRNView: UIView {
|
|
|
378
500
|
@objc func setAdaptiveVideo(_ val: Bool) {
|
|
379
501
|
guard let asset = self.asset,
|
|
380
502
|
val == true else {return}
|
|
381
|
-
|
|
503
|
+
|
|
382
504
|
asset.enableAutoAdaptation()
|
|
383
505
|
}
|
|
384
506
|
|
|
@@ -459,7 +581,8 @@ extension VdoCipherRNView: AssetPlaybackDelegate {
|
|
|
459
581
|
}
|
|
460
582
|
|
|
461
583
|
func streamPlaybackManager(playerCurrentItemDidChange player: AVPlayer) {
|
|
462
|
-
|
|
584
|
+
// Before setUpPlayer, which ignores players attached after the first.
|
|
585
|
+
player.isMuted = mutedState
|
|
463
586
|
self.setUpPlayer(player)
|
|
464
587
|
}
|
|
465
588
|
|
|
@@ -63,6 +63,8 @@ enum EventName: String, CaseIterable {
|
|
|
63
63
|
case EVENT_EXIT_FULLSCREEN = "onVdoExitFullscreen"
|
|
64
64
|
case EVENT_IS_INITIAL_PORTRAIT = "onIsInitialPortrait"
|
|
65
65
|
case EVENT_PICTURE_IN_PICTURE_MODE_CHANGED = "onVdoPictureInPictureModeChanged"
|
|
66
|
+
// Android only; listed so the shared JS listener is a supported event here too.
|
|
67
|
+
case EVENT_CAST_STATE_CHANGED = "onVdoCastStateChanged"
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
enum Keys: String {
|
|
@@ -18,4 +18,9 @@ class VdoPlaybackProperties: NSObject {
|
|
|
18
18
|
|
|
19
19
|
return ["totalPlayed": totalPlayed, "totalCovered": totalCovered]
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
// Exposed here because VdoCipherRNView has no stable Objective-C class name.
|
|
23
|
+
@objc static func isMuted() -> Bool {
|
|
24
|
+
return VdoCipherRNView.currentMuteState()
|
|
25
|
+
}
|
|
21
26
|
}
|
|
@@ -30,6 +30,10 @@ static inline void VdoHandlePlayerCommand(VdoCipherRNView *view, const NSString
|
|
|
30
30
|
[view setAdaptiveVideo:YES];
|
|
31
31
|
} else if ([commandName isEqualToString:@"setVideoQuality"] && args.count > 0) {
|
|
32
32
|
[view setVideoQuality:args[0]];
|
|
33
|
+
} else if ([commandName isEqualToString:@"mute"]) {
|
|
34
|
+
[view setMuted:YES];
|
|
35
|
+
} else if ([commandName isEqualToString:@"unmute"]) {
|
|
36
|
+
[view setMuted:NO];
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
|
|
@@ -15,4 +15,9 @@ class VdoPlayerSettings: NSObject {
|
|
|
15
15
|
}
|
|
16
16
|
VdoCipher.getVdoPlayerViewController().setBackgroundMode(vdoPlaybackMode)
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
// Android only; iOS PiP shows the system's own controls.
|
|
20
|
+
@objc func setPictureInPictureActionsEnabled(_ enabled: Bool) {
|
|
21
|
+
print("setPictureInPictureActionsEnabled method not supported in iOS")
|
|
22
|
+
}
|
|
18
23
|
}
|