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
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chromecast button (Android only). Wraps the native MediaRouteButton, which
|
|
3
|
+
* shows itself only when a cast device is available and opens the device chooser.
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { Platform, ViewProps, ColorValue } from 'react-native';
|
|
7
|
+
|
|
8
|
+
const NativeCastButton =
|
|
9
|
+
Platform.OS === 'android'
|
|
10
|
+
? require('./specs/RCTVdoCastButtonNativeComponent').default
|
|
11
|
+
: null;
|
|
12
|
+
|
|
13
|
+
type VdoCastButtonProps = ViewProps & { tint?: ColorValue };
|
|
14
|
+
|
|
15
|
+
const VdoCastButton = (props: VdoCastButtonProps) => {
|
|
16
|
+
if (!NativeCastButton) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return <NativeCastButton {...props} />;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default VdoCastButton;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chromecast mini controller (Android only). Hosts the SDK mini controller, which shows the current
|
|
3
|
+
* cast media and opens the expanded controller on tap. Mount it while casting (use the player's
|
|
4
|
+
* onCastStateChanged) and give it a height.
|
|
5
|
+
*/
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { Platform, ViewProps } from 'react-native';
|
|
8
|
+
|
|
9
|
+
const NativeCastMiniController =
|
|
10
|
+
Platform.OS === 'android'
|
|
11
|
+
? require('./specs/RCTVdoCastMiniControllerNativeComponent').default
|
|
12
|
+
: null;
|
|
13
|
+
|
|
14
|
+
const VdoCastMiniController = (props: ViewProps) => {
|
|
15
|
+
if (!NativeCastMiniController) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return <NativeCastMiniController {...props} />;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default VdoCastMiniController;
|
package/VdoPlayerView.tsx
CHANGED
|
@@ -82,6 +82,8 @@ class VdoPlayerView extends Component<MyProps, MyState> {
|
|
|
82
82
|
this._onPlaybackSpeedChanged(data);
|
|
83
83
|
})
|
|
84
84
|
|
|
85
|
+
this.eventEmitter.addListener('onVdoCastStateChanged', this._onCastStateChanged)
|
|
86
|
+
|
|
85
87
|
if (Platform.OS == "ios" && !(this.props.showNativeControls === false)) {
|
|
86
88
|
this.addFocusListeners();
|
|
87
89
|
}
|
|
@@ -100,6 +102,7 @@ class VdoPlayerView extends Component<MyProps, MyState> {
|
|
|
100
102
|
this.eventEmitter.removeAllListeners('onVdoEnterFullscreen');
|
|
101
103
|
this.eventEmitter.removeAllListeners('onVdoExitFullscreen');
|
|
102
104
|
this.eventEmitter.removeAllListeners('onVdoPlaybackSpeedChanged');
|
|
105
|
+
this.eventEmitter.removeAllListeners('onVdoCastStateChanged');
|
|
103
106
|
|
|
104
107
|
if (Platform.OS == "ios" && !(this.props.showNativeControls === false)) {
|
|
105
108
|
this.removeFocusListeners();
|
|
@@ -175,6 +178,60 @@ class VdoPlayerView extends Component<MyProps, MyState> {
|
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Android only. Works only with player with custom controls (showNativeControls={false})
|
|
183
|
+
*/
|
|
184
|
+
stopCasting = () => {
|
|
185
|
+
if (Platform.OS == "ios") {
|
|
186
|
+
console.warn("stopCasting not supported for ios");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (this._vdoPlayerView && this.props.showNativeControls === false) {
|
|
190
|
+
VdoPlayerCommands.stopCasting(this._vdoPlayerView._root);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Android only. Opens the native cast expanded controller. Works only with player with
|
|
196
|
+
* custom controls (showNativeControls={false}) while casting.
|
|
197
|
+
*/
|
|
198
|
+
openCastControls = () => {
|
|
199
|
+
if (Platform.OS == "ios") {
|
|
200
|
+
console.warn("openCastControls not supported for ios");
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (this._vdoPlayerView && this.props.showNativeControls === false) {
|
|
204
|
+
VdoPlayerCommands.openCastControls(this._vdoPlayerView._root);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Kept for the current video, including reloads; a new embedInfo starts with its startMuted.
|
|
210
|
+
* No effect on a Chromecast device.
|
|
211
|
+
*/
|
|
212
|
+
mute = () => {
|
|
213
|
+
if (this._vdoPlayerView) {
|
|
214
|
+
VdoPlayerCommands.mute(this._vdoPlayerView._root);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
unmute = () => {
|
|
219
|
+
if (this._vdoPlayerView) {
|
|
220
|
+
VdoPlayerCommands.unmute(this._vdoPlayerView._root);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Mute state of the most recently mounted player.
|
|
226
|
+
*/
|
|
227
|
+
isMuted = (): Promise<boolean> => {
|
|
228
|
+
return new Promise((resolve) => {
|
|
229
|
+
VdoPlayer.isMuted((muted: boolean) => {
|
|
230
|
+
resolve(muted);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
178
235
|
setPlaybackSpeed = (playbackSpeed: number) => {
|
|
179
236
|
if (this._vdoPlayerView) {
|
|
180
237
|
VdoPlayerCommands.playbackSpeed(this._vdoPlayerView._root, playbackSpeed);
|
|
@@ -377,6 +434,12 @@ class VdoPlayerView extends Component<MyProps, MyState> {
|
|
|
377
434
|
}
|
|
378
435
|
}
|
|
379
436
|
|
|
437
|
+
_onCastStateChanged = (event: any) => {
|
|
438
|
+
if (this.props.onCastStateChanged) {
|
|
439
|
+
this.props.onCastStateChanged(event.nativeEvent);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
380
443
|
render() {
|
|
381
444
|
return (
|
|
382
445
|
<Fragment>
|
|
@@ -399,6 +462,7 @@ class VdoPlayerView extends Component<MyProps, MyState> {
|
|
|
399
462
|
onVdoEnterFullscreen={this._onEnterFullscreen}
|
|
400
463
|
onVdoExitFullscreen={this._onExitFullscreen}
|
|
401
464
|
onVdoPictureInPictureModeChanged={this._onPictureInPictureModeChanged}
|
|
465
|
+
onVdoCastStateChanged={this._onCastStateChanged}
|
|
402
466
|
/>
|
|
403
467
|
) :
|
|
404
468
|
(
|
package/android/build.gradle
CHANGED
|
@@ -21,8 +21,8 @@ if (project.hasProperty("newArchEnabled") && project.newArchEnabled == "true") {
|
|
|
21
21
|
// TODO read from package.json
|
|
22
22
|
// "releaseVersionName" must be the same as "version" in package.json
|
|
23
23
|
// "releaseVersionCode" must increment by 1 with every release
|
|
24
|
-
def releaseVersionName = "2.0
|
|
25
|
-
def releaseVersionCode =
|
|
24
|
+
def releaseVersionName = "2.1.0"
|
|
25
|
+
def releaseVersionCode = 60
|
|
26
26
|
|
|
27
27
|
def isNewArchitectureEnabled() {
|
|
28
28
|
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
|
@@ -106,5 +106,7 @@ repositories {
|
|
|
106
106
|
dependencies {
|
|
107
107
|
compileOnly("com.facebook.react:react-native:+")
|
|
108
108
|
implementation("androidx.appcompat:appcompat:1.3.1")
|
|
109
|
-
implementation("com.vdocipher.aegis:vdocipher-android:1.
|
|
109
|
+
implementation("com.vdocipher.aegis:vdocipher-android:1.30.0")
|
|
110
|
+
implementation("androidx.mediarouter:mediarouter:1.8.1")
|
|
111
|
+
implementation("com.google.android.gms:play-services-cast-framework:22.1.0")
|
|
110
112
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
package com.vdocipher.
|
|
1
|
+
package com.vdocipher.rnbridge;
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.media.AudioAttributes;
|
|
5
5
|
import android.media.AudioFocusRequest;
|
|
6
6
|
import android.media.AudioManager;
|
|
7
7
|
import android.os.Build;
|
|
8
|
+
import android.os.Handler;
|
|
9
|
+
import android.os.Looper;
|
|
8
10
|
import androidx.appcompat.app.AppCompatActivity;
|
|
9
11
|
|
|
10
12
|
import androidx.annotation.NonNull;
|
|
@@ -14,6 +16,7 @@ import java.lang.ref.WeakReference;
|
|
|
14
16
|
public class AudioFocusManager {
|
|
15
17
|
private final WeakReference<AudioManager> audioManager;
|
|
16
18
|
private final AudioManager.OnAudioFocusChangeListener audioFocusChangeListener;
|
|
19
|
+
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
17
20
|
private AudioFocusRequest audioFocusRequest;
|
|
18
21
|
|
|
19
22
|
public AudioFocusManager(@NonNull AppCompatActivity activity, AudioManager.OnAudioFocusChangeListener audioFocusChangeListener) {
|
|
@@ -33,7 +36,9 @@ public class AudioFocusManager {
|
|
|
33
36
|
audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN)
|
|
34
37
|
.setAudioAttributes(audioAttributes)
|
|
35
38
|
.setAcceptsDelayedFocusGain(true)
|
|
36
|
-
|
|
39
|
+
// Without an explicit handler the callbacks are bound to the looper of
|
|
40
|
+
// whichever thread builds this, which under Fabric need not be the main one.
|
|
41
|
+
.setOnAudioFocusChangeListener(audioFocusChangeListener, mainHandler)
|
|
37
42
|
.build();
|
|
38
43
|
}
|
|
39
44
|
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
package com.vdocipher.rnbridge;
|
|
2
2
|
|
|
3
|
+
import com.facebook.react.bridge.Callback;
|
|
4
|
+
import com.facebook.react.bridge.UiThreadUtil;
|
|
5
|
+
|
|
6
|
+
import java.util.function.Consumer;
|
|
7
|
+
import java.util.function.Supplier;
|
|
8
|
+
|
|
3
9
|
public class PlayerViewRegistry {
|
|
4
10
|
private ReactVdoPlayerView playerView;
|
|
5
11
|
private ReactVdoPlayerUIView playerUIView;
|
|
@@ -31,4 +37,19 @@ public class PlayerViewRegistry {
|
|
|
31
37
|
public ReactVdoPlayerUIView getPlayerUIView() {
|
|
32
38
|
return playerUIView;
|
|
33
39
|
}
|
|
40
|
+
|
|
41
|
+
// Main thread is where views are registered and dropped, so the view cannot go away mid-call
|
|
42
|
+
public void withView(Callback callback, Supplier<Object> fallback,
|
|
43
|
+
Consumer<ReactVdoPlayerView> onPlayerView,
|
|
44
|
+
Consumer<ReactVdoPlayerUIView> onPlayerUIView) {
|
|
45
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
46
|
+
if (playerView != null) {
|
|
47
|
+
onPlayerView.accept(playerView);
|
|
48
|
+
} else if (playerUIView != null) {
|
|
49
|
+
onPlayerUIView.accept(playerUIView);
|
|
50
|
+
} else {
|
|
51
|
+
callback.invoke(fallback.get());
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
34
55
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
package com.vdocipher.rnbridge;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.res.TypedArray;
|
|
6
|
+
import android.graphics.drawable.Drawable;
|
|
7
|
+
import android.view.ContextThemeWrapper;
|
|
8
|
+
|
|
9
|
+
import androidx.annotation.Nullable;
|
|
10
|
+
import androidx.core.graphics.drawable.DrawableCompat;
|
|
11
|
+
|
|
12
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
13
|
+
|
|
14
|
+
public class ReactVdoCastButtonManagerImpl {
|
|
15
|
+
public static final String REACT_CLASS = "RCTVdoCastButton";
|
|
16
|
+
public static final String NEW_ARCH_REACT_CLASS = "VdoCastButton";
|
|
17
|
+
|
|
18
|
+
public VdoCastButtonView createViewInstance(ThemedReactContext context) {
|
|
19
|
+
// MediaRouteButton needs an AppCompat-themed context; the activity has one.
|
|
20
|
+
Activity activity = context.getCurrentActivity();
|
|
21
|
+
return new VdoCastButtonView(activity != null ? activity : context);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public void setTint(VdoCastButtonView view, @Nullable Integer color) {
|
|
25
|
+
if (color == null) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
Context themed = new ContextThemeWrapper(view.getContext(), androidx.mediarouter.R.style.Theme_MediaRouter);
|
|
29
|
+
TypedArray a = themed.obtainStyledAttributes(null,
|
|
30
|
+
androidx.mediarouter.R.styleable.MediaRouteButton,
|
|
31
|
+
androidx.mediarouter.R.attr.mediaRouteButtonStyle, 0);
|
|
32
|
+
Drawable drawable = a.getDrawable(androidx.mediarouter.R.styleable.MediaRouteButton_externalRouteEnabledDrawable);
|
|
33
|
+
a.recycle();
|
|
34
|
+
if (drawable != null) {
|
|
35
|
+
drawable = drawable.mutate();
|
|
36
|
+
DrawableCompat.setTint(drawable, color);
|
|
37
|
+
view.setRemoteIndicatorDrawable(drawable);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoCastMiniControllerManagerImpl.java
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
package com.vdocipher.rnbridge;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
4
|
+
|
|
5
|
+
public class ReactVdoCastMiniControllerManagerImpl {
|
|
6
|
+
public static final String REACT_CLASS = "RCTVdoCastMiniController";
|
|
7
|
+
public static final String NEW_ARCH_REACT_CLASS = "VdoCastMiniController";
|
|
8
|
+
|
|
9
|
+
public VdoCastMiniControllerView createViewInstance(ThemedReactContext context) {
|
|
10
|
+
return new VdoCastMiniControllerView(context);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -2,7 +2,6 @@ package com.vdocipher.rnbridge;
|
|
|
2
2
|
|
|
3
3
|
import androidx.appcompat.app.AppCompatActivity;
|
|
4
4
|
import androidx.fragment.app.FragmentManager;
|
|
5
|
-
import androidx.fragment.app.Fragment;
|
|
6
5
|
|
|
7
6
|
import android.util.Log;
|
|
8
7
|
import android.view.View;
|
|
@@ -67,6 +66,10 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
67
66
|
// from props
|
|
68
67
|
private boolean playWhenReady = true;
|
|
69
68
|
private float pendingPlaybackSpeed = 0;
|
|
69
|
+
// startMuted of new media, then the last mute/unmute. Re-applied while media loads: Aegis
|
|
70
|
+
// ignores mute until then, and a reload of the same media would reset it.
|
|
71
|
+
private boolean muted = false;
|
|
72
|
+
private VdoInitParams mutedForParams;
|
|
70
73
|
|
|
71
74
|
private VdoInitParams vdoParams;
|
|
72
75
|
private AppCompatActivity activity;
|
|
@@ -78,6 +81,8 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
78
81
|
private Track[] availableTracks;
|
|
79
82
|
private Track[] selectedTracks;
|
|
80
83
|
private Handler mainHandler;
|
|
84
|
+
// SDK callbacks can still arrive after cleanUp()
|
|
85
|
+
private boolean isDropped = false;
|
|
81
86
|
|
|
82
87
|
private int frameLayoutId;
|
|
83
88
|
|
|
@@ -97,6 +102,9 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
97
102
|
|
|
98
103
|
sharedPreferences = themedReactContext.getSharedPreferences(VDO_SHARED_PREFS, Context.MODE_PRIVATE);
|
|
99
104
|
|
|
105
|
+
// Assigned before the attach listener below, which reaches it through initializePlayer()
|
|
106
|
+
mainHandler = new Handler(Looper.getMainLooper());
|
|
107
|
+
|
|
100
108
|
FrameLayout frameLayout = new FrameLayout(context);
|
|
101
109
|
frameLayoutId = UUID.randomUUID().toString().hashCode();
|
|
102
110
|
frameLayout.setId(frameLayoutId);
|
|
@@ -106,6 +114,7 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
106
114
|
@Override
|
|
107
115
|
public void onViewAttachedToWindow(View v) {
|
|
108
116
|
Log.d(TAG, "onViewAttachedToWindow");
|
|
117
|
+
if (isDropped) return;
|
|
109
118
|
if (vdoPlayerUIFragment == null) {
|
|
110
119
|
vdoPlayerUIFragment = new VdoPlayerUIFragment();
|
|
111
120
|
Bundle bundle = new Bundle();
|
|
@@ -135,8 +144,6 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
135
144
|
|
|
136
145
|
context.addLifecycleEventListener(this);
|
|
137
146
|
|
|
138
|
-
mainHandler = new Handler(Looper.getMainLooper());
|
|
139
|
-
|
|
140
147
|
eventEmitter = new VdoEventEmitter(context);
|
|
141
148
|
|
|
142
149
|
setPictureInPictureSupport();
|
|
@@ -145,8 +152,9 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
145
152
|
|
|
146
153
|
private void initializePlayer() {
|
|
147
154
|
if (vdoPlayerUIFragment != null) {
|
|
148
|
-
|
|
149
|
-
|
|
155
|
+
mainHandler.postDelayed(() -> {
|
|
156
|
+
// The view can be unmounted during the delay, which clears the fragment in cleanUp()
|
|
157
|
+
if (vdoPlayerUIFragment != null && fragmentManager != null && !fragmentManager.isDestroyed()) {
|
|
150
158
|
try {
|
|
151
159
|
fragmentManager.beginTransaction().replace(frameLayoutId, vdoPlayerUIFragment, "VdoPlayerUIFragmentRN").commitAllowingStateLoss();
|
|
152
160
|
fragmentManager.executePendingTransactions();
|
|
@@ -171,43 +179,50 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
171
179
|
* Clean up all resources, references to this instance which may prevent it from being GC'ed.
|
|
172
180
|
*/
|
|
173
181
|
public void cleanUp() {
|
|
182
|
+
isDropped = true;
|
|
174
183
|
themedReactContext.removeLifecycleEventListener(this);
|
|
175
184
|
if (pictureModeChangedInfoConsumer != null) {
|
|
176
185
|
activity.removeOnPictureInPictureModeChangedListener(pictureModeChangedInfoConsumer);
|
|
177
186
|
}
|
|
178
187
|
|
|
188
|
+
// Drop any work still queued for this view, in particular the delayed transaction
|
|
189
|
+
// scheduled by initializePlayer(), which would otherwise keep it reachable
|
|
190
|
+
mainHandler.removeCallbacksAndMessages(null);
|
|
191
|
+
|
|
179
192
|
playbackMode = sharedPreferences.getString(VDO_PLAYBACK_MODE, null);
|
|
180
|
-
if (vdoPlayer != null
|
|
181
|
-
vdoPlayer.
|
|
193
|
+
if (vdoPlayer != null) {
|
|
194
|
+
vdoPlayer.removePlaybackEventListener(playbackListener);
|
|
195
|
+
if (VdoPlayerSetting.VdoPlaybackMode.DEFAULT == vdoPlaybackModeFromName(playbackMode)) {
|
|
196
|
+
vdoPlayer.stop();
|
|
197
|
+
}
|
|
182
198
|
}
|
|
183
|
-
if (fragmentManager != null && !fragmentManager.isDestroyed()) {
|
|
199
|
+
if (vdoPlayerUIFragment != null && fragmentManager != null && !fragmentManager.isDestroyed()) {
|
|
184
200
|
try {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
201
|
+
// Remove our own fragment rather than looking it up by id: when the delayed
|
|
202
|
+
// transaction never ran, getId() is still 0 and findFragmentById(0) matches
|
|
203
|
+
// any headless fragment in the activity
|
|
204
|
+
if (vdoPlayerUIFragment.isAdded()) {
|
|
205
|
+
fragmentManager.beginTransaction().remove(vdoPlayerUIFragment).commitAllowingStateLoss();
|
|
188
206
|
}
|
|
189
|
-
} catch(
|
|
207
|
+
} catch(Exception e) {
|
|
190
208
|
Log.e(TAG, Log.getStackTraceString(e));
|
|
191
209
|
}
|
|
192
210
|
}
|
|
193
211
|
vdoPlayerUIFragment = null;
|
|
212
|
+
vdoPlayer = null;
|
|
194
213
|
}
|
|
195
214
|
|
|
196
215
|
public void getPlaybackPropertiesV2(Callback callback) {
|
|
197
216
|
WritableMap playbackProperties = Arguments.createMap();
|
|
198
217
|
if (vdoPlayer != null) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
playbackProperties.putInt("totalCovered", (int)totalCovered);
|
|
206
|
-
callback.invoke(playbackProperties);
|
|
207
|
-
});
|
|
208
|
-
} else {
|
|
209
|
-
callback.invoke(playbackProperties);
|
|
218
|
+
Object tp = vdoPlayer.getPlaybackProperty("totalPlayed");
|
|
219
|
+
long totalPlayed = (tp instanceof Long) ? (long)tp : 0L;
|
|
220
|
+
Object tc = vdoPlayer.getPlaybackProperty("totalCovered");
|
|
221
|
+
long totalCovered = (tc instanceof Long) ? (long)tc : 0L;
|
|
222
|
+
playbackProperties.putInt("totalPlayed", (int)totalPlayed);
|
|
223
|
+
playbackProperties.putInt("totalCovered", (int)totalCovered);
|
|
210
224
|
}
|
|
225
|
+
callback.invoke(playbackProperties);
|
|
211
226
|
}
|
|
212
227
|
|
|
213
228
|
public void setPlayWhenReady(boolean playWhenReady) {
|
|
@@ -236,6 +251,27 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
236
251
|
}
|
|
237
252
|
}
|
|
238
253
|
|
|
254
|
+
// The fragment handles audio focus for mute changes.
|
|
255
|
+
public void setMuted(boolean muted) {
|
|
256
|
+
this.muted = muted;
|
|
257
|
+
applyMuted();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
public boolean isMuted() {
|
|
261
|
+
return muted;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private void applyMuted() {
|
|
265
|
+
if (vdoPlayer == null || vdoPlayer.isMuted() == muted) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (muted) {
|
|
269
|
+
vdoPlayer.mute();
|
|
270
|
+
} else {
|
|
271
|
+
vdoPlayer.unmute();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
239
275
|
public void setKeyDownEvent(KeyEvent event) {
|
|
240
276
|
if (vdoPlayerControlView != null && ! vdoPlayerControlView.controllerVisible()) {
|
|
241
277
|
vdoPlayerControlView.onKeyDown(event.getKeyCode(), event);
|
|
@@ -281,15 +317,7 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
281
317
|
}
|
|
282
318
|
|
|
283
319
|
public void isAdaptive(Callback callback) {
|
|
284
|
-
|
|
285
|
-
if (vdoPlayer != null) {
|
|
286
|
-
mainHandler.post(() -> {
|
|
287
|
-
boolean isAdaptive = vdoPlayer.isAdaptive();
|
|
288
|
-
callback.invoke(isAdaptive);
|
|
289
|
-
});
|
|
290
|
-
} else {
|
|
291
|
-
callback.invoke(false);
|
|
292
|
-
}
|
|
320
|
+
callback.invoke(vdoPlayer != null && vdoPlayer.isAdaptive());
|
|
293
321
|
}
|
|
294
322
|
|
|
295
323
|
public void getVideoQualities(Callback callback) {
|
|
@@ -333,47 +361,36 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
333
361
|
}
|
|
334
362
|
|
|
335
363
|
public void getDuration(Callback callback) {
|
|
336
|
-
|
|
337
|
-
if (vdoPlayer != null) {
|
|
338
|
-
mainHandler.post(() -> {
|
|
339
|
-
double videoDuration = vdoPlayer.getDuration();
|
|
340
|
-
WritableMap videoDurationMap = Arguments.createMap();
|
|
341
|
-
videoDurationMap.putDouble("duration", videoDuration);
|
|
342
|
-
callback.invoke(videoDurationMap);
|
|
343
|
-
});
|
|
344
|
-
} else {
|
|
364
|
+
if (vdoPlayer == null) {
|
|
345
365
|
callback.invoke(0);
|
|
366
|
+
return;
|
|
346
367
|
}
|
|
368
|
+
WritableMap videoDurationMap = Arguments.createMap();
|
|
369
|
+
videoDurationMap.putDouble("duration", vdoPlayer.getDuration());
|
|
370
|
+
callback.invoke(videoDurationMap);
|
|
347
371
|
}
|
|
348
372
|
|
|
349
373
|
public void setSelectedTrack(ReadableMap selectedTrackMap) {
|
|
350
374
|
Track selectedTrack = makeTrack(selectedTrackMap, availableTracks);
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
mainHandler.post(() -> {
|
|
354
|
-
vdoPlayer.setSelectedTracks(new Track[]{selectedTrack});
|
|
355
|
-
});
|
|
375
|
+
if (selectedTrack != null) {
|
|
376
|
+
postSelectTrack(selectedTrack);
|
|
356
377
|
}
|
|
357
378
|
}
|
|
358
379
|
|
|
359
380
|
public void enableAdaptiveVideo() {
|
|
360
|
-
Track
|
|
361
|
-
|
|
362
|
-
if (vdoPlayer != null) {
|
|
363
|
-
mainHandler.post(() -> {
|
|
364
|
-
vdoPlayer.setSelectedTracks(new Track[]{selectedTrack});
|
|
365
|
-
});
|
|
366
|
-
}
|
|
381
|
+
postSelectTrack(Track.SET_ADAPTIVE);
|
|
367
382
|
}
|
|
368
383
|
|
|
369
384
|
public void disableCaptions() {
|
|
370
|
-
Track
|
|
385
|
+
postSelectTrack(Track.DISABLE_CAPTIONS);
|
|
386
|
+
}
|
|
371
387
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
388
|
+
private void postSelectTrack(Track track) {
|
|
389
|
+
mainHandler.post(() -> {
|
|
390
|
+
if (vdoPlayer != null) {
|
|
391
|
+
vdoPlayer.setSelectedTracks(new Track[]{track});
|
|
392
|
+
}
|
|
393
|
+
});
|
|
377
394
|
}
|
|
378
395
|
|
|
379
396
|
@Override
|
|
@@ -450,6 +467,7 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
450
467
|
@Override
|
|
451
468
|
public void onInitializationSuccess(PlayerHost playerHost, VdoPlayer player, boolean restored) {
|
|
452
469
|
Log.d(TAG, "init success");
|
|
470
|
+
if (isDropped) return;
|
|
453
471
|
vdoPlayer = player;
|
|
454
472
|
availableTracks = vdoPlayer.getAvailableTracks();
|
|
455
473
|
selectedTracks = vdoPlayer.getSelectedTracks();
|
|
@@ -468,6 +486,7 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
468
486
|
public void onInitializationFailure(PlayerHost playerHost, ErrorDescription errorDescription) {
|
|
469
487
|
String msg = "onInitializationFailure: errorCode = " + errorDescription.errorCode + ": " + errorDescription.errorMsg;
|
|
470
488
|
Log.e(TAG, msg);
|
|
489
|
+
if (isDropped) return;
|
|
471
490
|
eventEmitter.initFailure(errorDescription);
|
|
472
491
|
}
|
|
473
492
|
|
|
@@ -478,6 +497,11 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
478
497
|
};
|
|
479
498
|
|
|
480
499
|
public void load(VdoInitParams params) {
|
|
500
|
+
// Equal params are the same media, which keeps its mute state.
|
|
501
|
+
if (params != null && !params.equals(mutedForParams)) {
|
|
502
|
+
mutedForParams = params;
|
|
503
|
+
muted = params.startMuted;
|
|
504
|
+
}
|
|
481
505
|
if (vdoPlayer != null && params != null) {
|
|
482
506
|
try {
|
|
483
507
|
vdoPlayer.load(params);
|
|
@@ -492,6 +516,7 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
492
516
|
private final VdoPlayer.PlaybackEventListener playbackListener = new VdoPlayer.PlaybackEventListener() {
|
|
493
517
|
@Override
|
|
494
518
|
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
|
519
|
+
applyMuted();
|
|
495
520
|
eventEmitter.playerStateChanged(playWhenReady, playbackState);
|
|
496
521
|
}
|
|
497
522
|
|
|
@@ -540,6 +565,7 @@ public class ReactVdoPlayerUIView extends LinearLayout implements LifecycleEvent
|
|
|
540
565
|
@Override
|
|
541
566
|
public void onLoaded(VdoInitParams vdoInitParams) {
|
|
542
567
|
Log.i(TAG, "onLoaded");
|
|
568
|
+
applyMuted();
|
|
543
569
|
vdoPlayer.setPlayWhenReady(playWhenReady);
|
|
544
570
|
if (pendingPlaybackSpeed > 0) {
|
|
545
571
|
vdoPlayer.setPlaybackSpeed(pendingPlaybackSpeed);
|
|
@@ -7,6 +7,7 @@ import com.facebook.react.bridge.ReadableMap;
|
|
|
7
7
|
import com.facebook.react.common.MapBuilder;
|
|
8
8
|
import com.facebook.react.uimanager.ThemedReactContext;
|
|
9
9
|
import com.vdocipher.aegis.player.VdoInitParams;
|
|
10
|
+
import com.vdocipher.aegis.player.VdoMediaMetadata;
|
|
10
11
|
import android.graphics.Color;
|
|
11
12
|
|
|
12
13
|
import org.json.JSONException;
|
|
@@ -16,6 +17,7 @@ import java.util.Map;
|
|
|
16
17
|
import javax.annotation.Nullable;
|
|
17
18
|
|
|
18
19
|
import static com.vdocipher.rnbridge.Utils.getTechOverride;
|
|
20
|
+
import static com.vdocipher.rnbridge.Utils.getVdoMediaMetadata;
|
|
19
21
|
import com.facebook.react.bridge.ReadableArray;
|
|
20
22
|
|
|
21
23
|
public class ReactVdoPlayerUIViewManagerImpl {
|
|
@@ -101,6 +103,12 @@ public class ReactVdoPlayerUIViewManagerImpl {
|
|
|
101
103
|
Log.e("VdoPlayer", "Invalid track payload", e);
|
|
102
104
|
}
|
|
103
105
|
break;
|
|
106
|
+
case "mute":
|
|
107
|
+
view.setMuted(true);
|
|
108
|
+
break;
|
|
109
|
+
case "unmute":
|
|
110
|
+
view.setMuted(false);
|
|
111
|
+
break;
|
|
104
112
|
}
|
|
105
113
|
}
|
|
106
114
|
|
|
@@ -140,6 +148,16 @@ public class ReactVdoPlayerUIViewManagerImpl {
|
|
|
140
148
|
int markerColorInt = Color.parseColor(clipMarkerColor);
|
|
141
149
|
builder.setClips(clipStartInMs, clipEndInMs, clipped, markerColorInt);
|
|
142
150
|
|
|
151
|
+
VdoMediaMetadata vdoMediaMetadata = getVdoMediaMetadata(embedInfo);
|
|
152
|
+
if (vdoMediaMetadata != null) {
|
|
153
|
+
builder.setVdoMediaMetadata(vdoMediaMetadata);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
builder.setStartMuted(embedInfo.hasKey("startMuted") && !embedInfo.isNull("startMuted")
|
|
157
|
+
&& embedInfo.getBoolean("startMuted"));
|
|
158
|
+
builder.setDisableAnalytics(embedInfo.hasKey("disableAnalytics") && !embedInfo.isNull("disableAnalytics")
|
|
159
|
+
&& embedInfo.getBoolean("disableAnalytics"));
|
|
160
|
+
|
|
143
161
|
if (offline) {
|
|
144
162
|
String mediaId = embedInfo.hasKey("mediaId") ? embedInfo.getString("mediaId") : null;
|
|
145
163
|
|