vdocipher-rn-bridge 1.9.1 → 1.10.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 +16 -0
- package/VdoPlayerSupportView.js +226 -0
- package/VdoPlayerUIView.js +271 -0
- package/VdoPlayerView.js +265 -202
- package/android/build.gradle +4 -5
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerUIView.java +306 -0
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerUIViewManager.java +156 -0
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerView.java +200 -61
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerViewManager.java +34 -38
- package/android/src/main/java/com/vdocipher/rnbridge/Utils.java +8 -0
- package/android/src/main/java/com/vdocipher/rnbridge/VdoDownloadModule.java +6 -5
- package/android/src/main/java/com/vdocipher/rnbridge/VdoEventEmitter.java +22 -2
- package/android/src/main/java/com/vdocipher/rnbridge/VdocipherRnBridgePackage.java +2 -1
- package/android/src/main/res/layout/activity_vdo_player_ui.xml +12 -0
- package/android/src/main/res/layout/activity_vdo_player_ui_custom.xml +12 -0
- package/downloadMonitor.js +2 -2
- package/package.json +4 -2
|
@@ -6,93 +6,101 @@ import android.util.Log;
|
|
|
6
6
|
import android.view.View;
|
|
7
7
|
import android.widget.FrameLayout;
|
|
8
8
|
import android.content.pm.ActivityInfo;
|
|
9
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
10
|
+
import androidx.fragment.app.FragmentManager;
|
|
9
11
|
|
|
12
|
+
import android.view.LayoutInflater;
|
|
13
|
+
|
|
14
|
+
import android.content.res.Configuration;
|
|
10
15
|
import com.facebook.react.bridge.LifecycleEventListener;
|
|
11
16
|
import com.facebook.react.uimanager.ThemedReactContext;
|
|
12
17
|
import com.vdocipher.aegis.media.ErrorDescription;
|
|
13
18
|
import com.vdocipher.aegis.media.Track;
|
|
14
|
-
import com.vdocipher.aegis.player.PlaybackState;
|
|
15
19
|
import com.vdocipher.aegis.player.VdoPlayer;
|
|
16
20
|
import com.vdocipher.aegis.player.PlayerHost;
|
|
17
21
|
import com.vdocipher.aegis.player.PlayerHost.InitializationListener;
|
|
18
22
|
import com.vdocipher.aegis.player.VdoPlayer.PlaybackEventListener;
|
|
19
23
|
import com.vdocipher.aegis.player.VdoInitParams;
|
|
20
|
-
import com.vdocipher.aegis.player.
|
|
24
|
+
import com.vdocipher.aegis.player.VdoPlayerSupportFragment;
|
|
25
|
+
import android.media.AudioManager;
|
|
26
|
+
import android.app.UiModeManager;
|
|
27
|
+
import android.content.Context;
|
|
28
|
+
|
|
29
|
+
import androidx.core.app.PictureInPictureModeChangedInfo;
|
|
30
|
+
import androidx.core.util.Consumer;
|
|
31
|
+
import android.support.v4.media.MediaMetadataCompat;
|
|
32
|
+
import android.support.v4.media.session.MediaControllerCompat;
|
|
33
|
+
import android.support.v4.media.session.MediaSessionCompat;
|
|
34
|
+
import android.support.v4.media.session.PlaybackStateCompat;
|
|
21
35
|
|
|
22
36
|
public class ReactVdoPlayerView extends FrameLayout implements InitializationListener,
|
|
23
|
-
PlaybackEventListener, LifecycleEventListener
|
|
37
|
+
PlaybackEventListener, LifecycleEventListener {
|
|
24
38
|
private static final String TAG = "ReactVdoPlayerView";
|
|
25
39
|
|
|
26
40
|
private final ThemedReactContext themedReactContext;
|
|
27
|
-
private
|
|
28
|
-
private final VdoPlayerControlView playerControlView;
|
|
41
|
+
private VdoPlayerSupportFragment vdoPlayerFragment;
|
|
29
42
|
private final VdoEventEmitter eventEmitter;
|
|
43
|
+
private AudioManager audioManager;
|
|
30
44
|
|
|
31
45
|
private VdoPlayer vdoPlayer;
|
|
32
46
|
|
|
33
47
|
// from props
|
|
34
|
-
private boolean showNativeControls = true;
|
|
35
48
|
private boolean playWhenReady = true;
|
|
36
49
|
private float pendingPlaybackSpeed = 0;
|
|
37
50
|
private boolean fullscreen = false;
|
|
38
51
|
|
|
52
|
+
private boolean hasPictureInPictureSupport = false;
|
|
53
|
+
private MediaSessionCompat mSession;
|
|
54
|
+
public static final long MEDIA_ACTIONS_PLAY_PAUSE =
|
|
55
|
+
PlaybackStateCompat.ACTION_PLAY
|
|
56
|
+
| PlaybackStateCompat.ACTION_PAUSE
|
|
57
|
+
| PlaybackStateCompat.ACTION_PLAY_PAUSE;
|
|
58
|
+
|
|
39
59
|
private VdoInitParams pendingInitParams;
|
|
40
|
-
|
|
41
|
-
private
|
|
60
|
+
|
|
61
|
+
private AppCompatActivity activity;
|
|
62
|
+
|
|
63
|
+
private Consumer<PictureInPictureModeChangedInfo> pictureModeChangedInfoConsumer;
|
|
42
64
|
|
|
43
65
|
public ReactVdoPlayerView(ThemedReactContext context) {
|
|
44
66
|
super(context);
|
|
45
67
|
context.addLifecycleEventListener(this);
|
|
46
68
|
themedReactContext = context;
|
|
47
69
|
|
|
48
|
-
playerView = new VdoPlayerView(context);
|
|
49
|
-
playerControlView = new VdoPlayerControlView(context);
|
|
50
|
-
playerControlView.setFullscreenActionListener(this);
|
|
51
70
|
eventEmitter = new VdoEventEmitter(context);
|
|
52
71
|
|
|
53
|
-
|
|
72
|
+
LayoutInflater.from(context).inflate(R.layout.activity_vdo_player_ui_custom, this);
|
|
73
|
+
|
|
74
|
+
activity = (AppCompatActivity) themedReactContext.getCurrentActivity();
|
|
75
|
+
vdoPlayerFragment = (VdoPlayerSupportFragment) activity.getSupportFragmentManager().findFragmentById(R.id.online_vdo_player_support_fragment);
|
|
54
76
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
77
|
+
initializePlayer();
|
|
78
|
+
|
|
79
|
+
int orientation = getResources().getConfiguration().orientation;
|
|
80
|
+
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
81
|
+
eventEmitter.isInitialPortrait();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
|
|
85
|
+
|
|
86
|
+
}
|
|
59
87
|
|
|
60
|
-
|
|
88
|
+
private void initializePlayer() {
|
|
89
|
+
if (vdoPlayerFragment != null) {
|
|
90
|
+
// initialize the playerFragment; a VdoPlayer instance will be received
|
|
91
|
+
// in onInitializationSuccess() callback
|
|
92
|
+
vdoPlayerFragment.initialize(this);
|
|
93
|
+
}
|
|
61
94
|
}
|
|
62
95
|
|
|
63
96
|
/**
|
|
64
97
|
* Clean up all resources, references to this instance which may prevent it from being GC'ed.
|
|
65
98
|
*/
|
|
66
99
|
public void cleanUp() {
|
|
67
|
-
stopPlayback();
|
|
68
100
|
themedReactContext.removeLifecycleEventListener(this);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Frees resources used by player. Does not lose player instance.
|
|
73
|
-
*/
|
|
74
|
-
public void stopPlayback() {
|
|
75
|
-
stopped = true;
|
|
76
|
-
playbackState = playerView.getLastPlaybackState();
|
|
77
|
-
playerView.packUp();
|
|
78
|
-
|
|
79
|
-
setKeepScreenOn(false);
|
|
80
|
-
if (fullscreen) {
|
|
81
|
-
setFullscreen(false);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public void restorePlayback() {
|
|
86
|
-
if (stopped && playbackState != null) {
|
|
87
|
-
playerView.restore(playbackState);
|
|
88
|
-
setKeepScreenOn(true);
|
|
101
|
+
if (hasPictureInPictureSupport && pictureModeChangedInfoConsumer != null) {
|
|
102
|
+
activity.removeOnPictureInPictureModeChangedListener(pictureModeChangedInfoConsumer);
|
|
89
103
|
}
|
|
90
|
-
stopped = false;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public void showNativeControls(boolean showNativeControls) {
|
|
94
|
-
this.showNativeControls = showNativeControls;
|
|
95
|
-
playerControlView.setVisibility(showNativeControls ? VISIBLE : GONE);
|
|
96
104
|
}
|
|
97
105
|
|
|
98
106
|
public boolean setFullscreen(boolean enterFullscreen) {
|
|
@@ -100,7 +108,6 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
|
|
|
100
108
|
return false;
|
|
101
109
|
}
|
|
102
110
|
|
|
103
|
-
Activity activity = themedReactContext.getCurrentActivity();
|
|
104
111
|
if (activity == null) {
|
|
105
112
|
return false;
|
|
106
113
|
}
|
|
@@ -151,7 +158,7 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
|
|
|
151
158
|
}
|
|
152
159
|
|
|
153
160
|
public void setPlaybackSpeed(float playbackSpeed) {
|
|
154
|
-
|
|
161
|
+
pendingPlaybackSpeed = playbackSpeed;
|
|
155
162
|
if (vdoPlayer != null) {
|
|
156
163
|
vdoPlayer.setPlaybackSpeed(playbackSpeed);
|
|
157
164
|
}
|
|
@@ -163,12 +170,105 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
|
|
|
163
170
|
}
|
|
164
171
|
}
|
|
165
172
|
|
|
173
|
+
public void setPictureInPictureSupport() {
|
|
174
|
+
if (!isRunningOnTv()) {
|
|
175
|
+
hasPictureInPictureSupport = true;
|
|
176
|
+
pictureModeChangedInfoConsumer = pictureInPictureModeChangedInfo ->
|
|
177
|
+
{
|
|
178
|
+
eventEmitter.onPictureInPictureModeChanged(pictureInPictureModeChangedInfo.isInPictureInPictureMode());
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
activity.addOnPictureInPictureModeChangedListener(pictureModeChangedInfoConsumer);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private void initializeMediaSession() {
|
|
186
|
+
mSession = new MediaSessionCompat(activity, TAG);
|
|
187
|
+
mSession.setActive(true);
|
|
188
|
+
MediaControllerCompat.setMediaController(activity, mSession.getController());
|
|
189
|
+
|
|
190
|
+
MediaMetadataCompat metadata = new MediaMetadataCompat.Builder().build();
|
|
191
|
+
mSession.setMetadata(metadata);
|
|
192
|
+
|
|
193
|
+
MediaSessionCallback mMediaSessionCallback = new MediaSessionCallback(vdoPlayer);
|
|
194
|
+
mSession.setCallback(mMediaSessionCallback);
|
|
195
|
+
|
|
196
|
+
boolean playing = vdoPlayer != null && vdoPlayer.getPlaybackState() != VdoPlayer.STATE_IDLE && vdoPlayer.getPlaybackState() != VdoPlayer.STATE_ENDED && vdoPlayer.getPlayWhenReady();
|
|
197
|
+
|
|
198
|
+
int state = playing ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED;
|
|
199
|
+
|
|
200
|
+
if (vdoPlayer != null) {
|
|
201
|
+
updatePlaybackState(state, MEDIA_ACTIONS_PLAY_PAUSE, vdoPlayer.getCurrentTime(), vdoPlayer.getPlaybackSpeed());
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Overloaded method that persists previously set media actions.
|
|
207
|
+
*
|
|
208
|
+
* @param state The state of the video, e.g. playing, paused, etc.
|
|
209
|
+
* @param position The position of playback in the video.
|
|
210
|
+
*/
|
|
211
|
+
private void updatePlaybackState(
|
|
212
|
+
@PlaybackStateCompat.State int state, long position, float playBackSpeed) {
|
|
213
|
+
long actions = mSession.getController().getPlaybackState().getActions();
|
|
214
|
+
updatePlaybackState(state, actions, position, playBackSpeed);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private void updatePlaybackState(
|
|
218
|
+
@PlaybackStateCompat.State int state, long playbackActions, long position, float playBackSpeed) {
|
|
219
|
+
PlaybackStateCompat.Builder builder =
|
|
220
|
+
new PlaybackStateCompat.Builder()
|
|
221
|
+
.setActions(playbackActions)
|
|
222
|
+
.setState(state, position, playBackSpeed);
|
|
223
|
+
mSession.setPlaybackState(builder.build());
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private static class MediaSessionCallback extends MediaSessionCompat.Callback {
|
|
227
|
+
|
|
228
|
+
private final VdoPlayer player;
|
|
229
|
+
|
|
230
|
+
public MediaSessionCallback(VdoPlayer player) {
|
|
231
|
+
this.player = player;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@Override
|
|
235
|
+
public void onPlay() {
|
|
236
|
+
super.onPlay();
|
|
237
|
+
//resume playing
|
|
238
|
+
player.setPlayWhenReady(true);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
@Override
|
|
242
|
+
public void onPause() {
|
|
243
|
+
super.onPause();
|
|
244
|
+
//pause playing
|
|
245
|
+
player.setPlayWhenReady(false);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
@Override
|
|
249
|
+
public void onSkipToNext() {
|
|
250
|
+
super.onSkipToNext();
|
|
251
|
+
//Implement this according to your app needs
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
@Override
|
|
255
|
+
public void onSkipToPrevious() {
|
|
256
|
+
super.onSkipToPrevious();
|
|
257
|
+
//Implement this according to your app needs
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
166
261
|
@Override
|
|
167
262
|
public void setId(int id) {
|
|
168
263
|
super.setId(id);
|
|
169
264
|
eventEmitter.setViewId(id);
|
|
170
265
|
}
|
|
171
266
|
|
|
267
|
+
private boolean isRunningOnTv() {
|
|
268
|
+
UiModeManager uiModeManager = (UiModeManager) activity.getSystemService(Context.UI_MODE_SERVICE);
|
|
269
|
+
return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
|
|
270
|
+
}
|
|
271
|
+
|
|
172
272
|
@Override
|
|
173
273
|
protected void onAttachedToWindow() {
|
|
174
274
|
Log.d(TAG, "onAttachedToWindow");
|
|
@@ -178,30 +278,23 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
|
|
|
178
278
|
@Override
|
|
179
279
|
protected void onDetachedFromWindow() {
|
|
180
280
|
Log.d(TAG, "onDetachedFromWindow");
|
|
281
|
+
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
282
|
+
if (fragmentManager != null && !fragmentManager.isDestroyed()) {
|
|
283
|
+
fragmentManager.beginTransaction().remove(vdoPlayerFragment).commitNow();
|
|
284
|
+
}
|
|
181
285
|
super.onDetachedFromWindow();
|
|
182
286
|
}
|
|
183
287
|
|
|
184
|
-
// FullscreenActionListener impl
|
|
185
|
-
|
|
186
|
-
@Override
|
|
187
|
-
public boolean onFullscreenAction(boolean enterFullscreen) {
|
|
188
|
-
return setFullscreen(enterFullscreen);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
288
|
// LifecycleEventListener impl
|
|
193
289
|
|
|
194
290
|
@Override
|
|
195
291
|
public void onHostResume() {
|
|
196
292
|
Log.d(TAG, "onHostResume");
|
|
197
|
-
restorePlayback();
|
|
198
|
-
playerControlView.setFullscreenState(fullscreen);
|
|
199
293
|
}
|
|
200
294
|
|
|
201
295
|
@Override
|
|
202
296
|
public void onHostPause() {
|
|
203
297
|
Log.d(TAG, "onHostPause");
|
|
204
|
-
stopPlayback();
|
|
205
298
|
}
|
|
206
299
|
|
|
207
300
|
@Override
|
|
@@ -219,18 +312,18 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
|
|
|
219
312
|
Log.d(TAG, "init success");
|
|
220
313
|
this.vdoPlayer = vdoPlayer;
|
|
221
314
|
vdoPlayer.addPlaybackEventListener(this);
|
|
222
|
-
playerControlView.setPlayer(vdoPlayer);
|
|
223
315
|
eventEmitter.initSuccess(restored);
|
|
224
316
|
|
|
225
|
-
// don't continue to playback if stopped
|
|
226
|
-
if (stopped) return;
|
|
227
|
-
|
|
228
317
|
// load pending params
|
|
229
318
|
if (pendingInitParams != null) {
|
|
230
319
|
Log.d(TAG, "load pending params");
|
|
231
320
|
load(pendingInitParams);
|
|
232
321
|
pendingInitParams = null;
|
|
233
322
|
}
|
|
323
|
+
|
|
324
|
+
if (hasPictureInPictureSupport) {
|
|
325
|
+
initializeMediaSession();
|
|
326
|
+
}
|
|
234
327
|
}
|
|
235
328
|
|
|
236
329
|
@Override
|
|
@@ -251,9 +344,55 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
|
|
|
251
344
|
|
|
252
345
|
@Override
|
|
253
346
|
public void onPlayerStateChanged(boolean playWhenReady, int playerState) {
|
|
347
|
+
boolean playing = playerState != VdoPlayer.STATE_IDLE && playerState != VdoPlayer.STATE_ENDED && playWhenReady;
|
|
348
|
+
|
|
349
|
+
// We are playing the video now. Update the media session state and the PiP
|
|
350
|
+
// window will update the actions.
|
|
351
|
+
|
|
352
|
+
if (hasPictureInPictureSupport) {
|
|
353
|
+
updatePlaybackState(playing ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED, vdoPlayer.getCurrentTime(), vdoPlayer.getPlaybackSpeed());
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (playing) {
|
|
357
|
+
//Request audio focus and notify other players to stop playback.
|
|
358
|
+
if (!requestAudioFocus(audioManager)) {
|
|
359
|
+
Log.i(TAG, "Audio focus not granted");
|
|
360
|
+
}
|
|
361
|
+
} else if (playerState == VdoPlayer.STATE_ENDED) {
|
|
362
|
+
// Abandon audio focus when playback complete
|
|
363
|
+
audioManager.abandonAudioFocus(audioFocusChangeListener);
|
|
364
|
+
}
|
|
254
365
|
eventEmitter.playerStateChanged(playWhenReady, playerState);
|
|
255
366
|
}
|
|
256
367
|
|
|
368
|
+
private boolean requestAudioFocus(AudioManager audioManager) {
|
|
369
|
+
return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == audioManager.requestAudioFocus(audioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
private final AudioManager.OnAudioFocusChangeListener audioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() {
|
|
373
|
+
@Override
|
|
374
|
+
public void onAudioFocusChange(int focusChange) {
|
|
375
|
+
switch (focusChange) {
|
|
376
|
+
case AudioManager.AUDIOFOCUS_GAIN:
|
|
377
|
+
//resume playing
|
|
378
|
+
if (vdoPlayer != null)
|
|
379
|
+
vdoPlayer.setPlayWhenReady(true);
|
|
380
|
+
break;
|
|
381
|
+
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
|
|
382
|
+
//depending on your app reduce audio to a minimum if you want to continue playing or pause
|
|
383
|
+
break;
|
|
384
|
+
case AudioManager.AUDIOFOCUS_LOSS:
|
|
385
|
+
//pause playing
|
|
386
|
+
if (vdoPlayer != null)
|
|
387
|
+
vdoPlayer.setPlayWhenReady(false);
|
|
388
|
+
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
|
|
389
|
+
default:
|
|
390
|
+
//stop playing
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
|
|
257
396
|
@Override
|
|
258
397
|
public void onSeekTo(long timeMs) {
|
|
259
398
|
eventEmitter.seekTo(timeMs);
|
|
@@ -54,25 +54,32 @@ public class ReactVdoPlayerViewManager extends ViewGroupManager<ReactVdoPlayerVi
|
|
|
54
54
|
boolean offline = embedInfo.hasKey("offline") && embedInfo.getBoolean("offline");
|
|
55
55
|
final VdoInitParams initParams;
|
|
56
56
|
boolean enableAutoResume = embedInfo.hasKey("enableAutoResume") && embedInfo.getBoolean("enableAutoResume");
|
|
57
|
+
String preferredCaptionsLanguage = embedInfo.hasKey("preferredCaptionsLanguage") ?
|
|
58
|
+
embedInfo.getString("preferredCaptionsLanguage") : null;
|
|
59
|
+
String safetyNetApiKey = embedInfo.hasKey("safetyNetApiKey") ?
|
|
60
|
+
embedInfo.getString("safetyNetApiKey") : null;
|
|
61
|
+
boolean allowAdbDebugging = !embedInfo.hasKey("allowAdbDebugging") ||
|
|
62
|
+
embedInfo.getBoolean("allowAdbDebugging");
|
|
63
|
+
boolean setPictureInPictureSupport = embedInfo.hasKey("setPictureInPictureSupport") && embedInfo.getBoolean("setPictureInPictureSupport");
|
|
64
|
+
|
|
65
|
+
VdoInitParams.Builder builder = new VdoInitParams.Builder();
|
|
66
|
+
|
|
67
|
+
if (enableAutoResume) {
|
|
68
|
+
builder.enableAutoResume();
|
|
69
|
+
}
|
|
70
|
+
if (safetyNetApiKey != null) {
|
|
71
|
+
builder.setSafetyNetApiKey(safetyNetApiKey);
|
|
72
|
+
}
|
|
73
|
+
if (preferredCaptionsLanguage != null) {
|
|
74
|
+
builder.setPreferredCaptionsLanguage(preferredCaptionsLanguage);
|
|
75
|
+
}
|
|
57
76
|
|
|
58
77
|
if (offline) {
|
|
59
78
|
String mediaId = embedInfo.hasKey("mediaId") ? embedInfo.getString("mediaId") : null;
|
|
60
|
-
String safetyNetApiKey = embedInfo.hasKey("safetyNetApiKey") ?
|
|
61
|
-
embedInfo.getString("safetyNetApiKey") : null;
|
|
62
|
-
boolean allowAdbDebugging = !embedInfo.hasKey("allowAdbDebugging") ||
|
|
63
|
-
embedInfo.getBoolean("allowAdbDebugging");
|
|
64
79
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
.setAllowAdbDebugging(allowAdbDebugging);
|
|
80
|
+
builder.setOfflinePlayback(mediaId)
|
|
81
|
+
.setAllowAdbDebugging(allowAdbDebugging);
|
|
68
82
|
|
|
69
|
-
if (enableAutoResume) {
|
|
70
|
-
builder.enableAutoResume();
|
|
71
|
-
}
|
|
72
|
-
if (safetyNetApiKey != null) {
|
|
73
|
-
builder.setSafetyNetApiKey(safetyNetApiKey);
|
|
74
|
-
}
|
|
75
|
-
initParams = builder.build();
|
|
76
83
|
} else {
|
|
77
84
|
String otp = embedInfo.hasKey("otp") ? embedInfo.getString("otp") : null;
|
|
78
85
|
String playbackInfo = embedInfo.hasKey("playbackInfo") ? embedInfo.getString("playbackInfo") : null;
|
|
@@ -85,43 +92,32 @@ public class ReactVdoPlayerViewManager extends ViewGroupManager<ReactVdoPlayerVi
|
|
|
85
92
|
int bufferingGoalMs = embedInfo.hasKey("bufferingGoalMs") ?
|
|
86
93
|
embedInfo.getInt("bufferingGoalMs") : 0;
|
|
87
94
|
String[] overrides = getTechOverride(embedInfo);
|
|
88
|
-
String safetyNetApiKey = embedInfo.hasKey("safetyNetApiKey") ?
|
|
89
|
-
embedInfo.getString("safetyNetApiKey") : null;
|
|
90
|
-
boolean allowAdbDebugging = !embedInfo.hasKey("allowAdbDebugging") ||
|
|
91
|
-
embedInfo.getBoolean("allowAdbDebugging");
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
.setMaxVideoBitrateKbps(maxVideoBitrateKbps);
|
|
100
|
-
//.setPreferredCaptionsLanguage(embedInfo.getString("lang??"))
|
|
96
|
+
builder.setOtp(otp)
|
|
97
|
+
.setPlaybackInfo(playbackInfo)
|
|
98
|
+
.setAllowAdbDebugging(allowAdbDebugging)
|
|
99
|
+
.setForceLowestBitrate(forceLowestBitrate)
|
|
100
|
+
.setForceHighestSupportedBitrate(forceHighestSupportedBitrate)
|
|
101
|
+
.setMaxVideoBitrateKbps(maxVideoBitrateKbps);
|
|
101
102
|
|
|
102
|
-
if (enableAutoResume) {
|
|
103
|
-
builder.enableAutoResume();
|
|
104
|
-
}
|
|
105
103
|
if (bufferingGoalMs > 0) {
|
|
106
104
|
builder.setBufferingGoalMs(bufferingGoalMs);
|
|
107
105
|
}
|
|
108
106
|
if (overrides != null) {
|
|
109
107
|
builder.setTechOverride(overrides);
|
|
110
108
|
}
|
|
111
|
-
if (safetyNetApiKey != null) {
|
|
112
|
-
builder.setSafetyNetApiKey(safetyNetApiKey);
|
|
113
|
-
}
|
|
114
|
-
initParams = builder.build();
|
|
115
109
|
}
|
|
110
|
+
|
|
111
|
+
initParams = builder.build();
|
|
112
|
+
|
|
113
|
+
if (setPictureInPictureSupport) {
|
|
114
|
+
vdoPlayerView.setPictureInPictureSupport();
|
|
115
|
+
}
|
|
116
|
+
|
|
116
117
|
vdoPlayerView.load(initParams);
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
@ReactProp(name = "showNativeControls", defaultBoolean = true)
|
|
121
|
-
public void setShowNativeControls(ReactVdoPlayerView vdoPlayerView, boolean showNativeControls) {
|
|
122
|
-
vdoPlayerView.showNativeControls(showNativeControls);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
121
|
@ReactProp(name = "playWhenReady", defaultBoolean = true)
|
|
126
122
|
public void setPlayWhenReady(ReactVdoPlayerView vdoPlayerView, boolean playWhenReady) {
|
|
127
123
|
vdoPlayerView.setPlayWhenReady(playWhenReady);
|
|
@@ -171,6 +171,10 @@ public class Utils {
|
|
|
171
171
|
return VdoDownloadManager.STATUS_COMPLETED;
|
|
172
172
|
case "failed":
|
|
173
173
|
return VdoDownloadManager.STATUS_FAILED;
|
|
174
|
+
case "removing":
|
|
175
|
+
return VdoDownloadManager.STATUS_REMOVING;
|
|
176
|
+
case "restarting":
|
|
177
|
+
return VdoDownloadManager.STATUS_RESTARTING;
|
|
174
178
|
default:
|
|
175
179
|
throw new IllegalArgumentException("Unknown status");
|
|
176
180
|
}
|
|
@@ -188,6 +192,10 @@ public class Utils {
|
|
|
188
192
|
return "completed";
|
|
189
193
|
case VdoDownloadManager.STATUS_FAILED:
|
|
190
194
|
return "failed";
|
|
195
|
+
case VdoDownloadManager.STATUS_REMOVING:
|
|
196
|
+
return "removing";
|
|
197
|
+
case VdoDownloadManager.STATUS_RESTARTING:
|
|
198
|
+
return "restarting";
|
|
191
199
|
default:
|
|
192
200
|
throw new IllegalArgumentException("Unknown status");
|
|
193
201
|
}
|
|
@@ -63,10 +63,10 @@ public class VdoDownloadModule extends ReactContextBaseJavaModule implements Vdo
|
|
|
63
63
|
String otp = optionParams.getString("otp");
|
|
64
64
|
String playbackInfo = optionParams.getString("playbackInfo");
|
|
65
65
|
|
|
66
|
-
OptionsDownloader optionsDownloader = new OptionsDownloader();
|
|
66
|
+
OptionsDownloader optionsDownloader = new OptionsDownloader(getReactApplicationContext());
|
|
67
67
|
|
|
68
68
|
try {
|
|
69
|
-
optionsDownloader.downloadOptionsWithOtp(otp, playbackInfo, new OptionsDownloader.Callback() {
|
|
69
|
+
optionsDownloader.downloadOptionsWithOtp(otp, playbackInfo, null, new OptionsDownloader.Callback() {
|
|
70
70
|
@Override
|
|
71
71
|
public void onOptionsReceived(DownloadOptions options) {
|
|
72
72
|
Log.i(TAG, "onOptionsReceived");
|
|
@@ -74,6 +74,7 @@ public class VdoDownloadModule extends ReactContextBaseJavaModule implements Vdo
|
|
|
74
74
|
successCallback.invoke(
|
|
75
75
|
playbackInfo, /* nativeId */
|
|
76
76
|
makeDownloadOptionsMap(options)
|
|
77
|
+
|
|
77
78
|
);
|
|
78
79
|
}
|
|
79
80
|
|
|
@@ -239,13 +240,13 @@ public class VdoDownloadModule extends ReactContextBaseJavaModule implements Vdo
|
|
|
239
240
|
DownloadSelections downloadSelections = new DownloadSelections(downloadOptions, selectedIndices);
|
|
240
241
|
|
|
241
242
|
// Build a DownloadRequest
|
|
242
|
-
DownloadRequest request = new DownloadRequest.Builder(downloadSelections
|
|
243
|
+
DownloadRequest request = new DownloadRequest.Builder(downloadSelections).build();
|
|
243
244
|
|
|
244
|
-
VdoDownloadManager vdoDownloadManager = VdoDownloadManager.getInstance(getReactApplicationContext());
|
|
245
|
+
VdoDownloadManager vdoDownloadManager = VdoDownloadManager.getInstance(getReactApplicationContext(), downloadLocation);
|
|
245
246
|
|
|
246
247
|
// Enqueue request to VdoDownloadManager for download
|
|
247
248
|
try {
|
|
248
|
-
vdoDownloadManager.
|
|
249
|
+
vdoDownloadManager.enqueueV2(request);
|
|
249
250
|
successCallback.invoke();
|
|
250
251
|
} catch (IllegalArgumentException | IllegalStateException e) {
|
|
251
252
|
Log.e(TAG, "enqueue failed: " + Log.getStackTraceString(e));
|
|
@@ -33,6 +33,9 @@ class VdoEventEmitter {
|
|
|
33
33
|
private static final String EVENT_PLAYBACK_PROPERTIES = "onVdoPlaybackProperties";
|
|
34
34
|
private static final String EVENT_ENTER_FULLSCREEN = "onVdoEnterFullscreen";
|
|
35
35
|
private static final String EVENT_EXIT_FULLSCREEN = "onVdoExitFullscreen";
|
|
36
|
+
private static final String EVENT_IS_INITIAL_PORTRAIT = "onIsInitialPortrait";
|
|
37
|
+
private static final String EVENT_PICTURE_IN_PICTURE_MODE_CHANGED ="onVdoPictureInPictureModeChanged";
|
|
38
|
+
|
|
36
39
|
|
|
37
40
|
static final String[] EVENTS = {
|
|
38
41
|
EVENT_INIT_SUCCESS, EVENT_INIT_FAILURE,
|
|
@@ -43,7 +46,9 @@ class VdoEventEmitter {
|
|
|
43
46
|
EVENT_MEDIA_ENDED,
|
|
44
47
|
EVENT_ERROR,
|
|
45
48
|
EVENT_PLAYBACK_PROPERTIES,
|
|
46
|
-
EVENT_ENTER_FULLSCREEN, EVENT_EXIT_FULLSCREEN
|
|
49
|
+
EVENT_ENTER_FULLSCREEN, EVENT_EXIT_FULLSCREEN,
|
|
50
|
+
EVENT_IS_INITIAL_PORTRAIT,
|
|
51
|
+
EVENT_PICTURE_IN_PICTURE_MODE_CHANGED
|
|
47
52
|
};
|
|
48
53
|
|
|
49
54
|
@Retention(RetentionPolicy.SOURCE)
|
|
@@ -55,7 +60,8 @@ class VdoEventEmitter {
|
|
|
55
60
|
EVENT_MEDIA_ENDED,
|
|
56
61
|
EVENT_ERROR,
|
|
57
62
|
EVENT_PLAYBACK_PROPERTIES,
|
|
58
|
-
EVENT_ENTER_FULLSCREEN, EVENT_EXIT_FULLSCREEN
|
|
63
|
+
EVENT_ENTER_FULLSCREEN, EVENT_EXIT_FULLSCREEN,
|
|
64
|
+
EVENT_IS_INITIAL_PORTRAIT, EVENT_PICTURE_IN_PICTURE_MODE_CHANGED})
|
|
59
65
|
@interface VdoEvent {}
|
|
60
66
|
|
|
61
67
|
private static final String EVENT_PROP_RESTORED = "restored";
|
|
@@ -71,6 +77,8 @@ class VdoEventEmitter {
|
|
|
71
77
|
private static final String EVENT_PROP_PLAY_WHEN_READY = "playWhenReady";
|
|
72
78
|
private static final String EVENT_PROP_PLAYER_STATE = "playerState";
|
|
73
79
|
private static final String EVENT_PROP_PLAYBACK_SPEED = "playbackSpeed";
|
|
80
|
+
private static final String EVENT_PROP_IS_INITIAL_PORTRAIT = "isInitialPortrait";
|
|
81
|
+
private static final String EVENT_PROP_IS_IN_PICTURE_IN_PICTURE_MODE = "isInPictureInPictureMode";
|
|
74
82
|
|
|
75
83
|
private static final String EVENT_PROP_ERROR_DESCRIPTION = "errorDescription";
|
|
76
84
|
|
|
@@ -176,6 +184,12 @@ class VdoEventEmitter {
|
|
|
176
184
|
receiveEvent(EVENT_EXIT_FULLSCREEN, null);
|
|
177
185
|
}
|
|
178
186
|
|
|
187
|
+
void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
|
|
188
|
+
WritableMap event = Arguments.createMap();
|
|
189
|
+
event.putBoolean(EVENT_PROP_IS_IN_PICTURE_IN_PICTURE_MODE, isInPictureInPictureMode);
|
|
190
|
+
receiveEvent(EVENT_PICTURE_IN_PICTURE_MODE_CHANGED, event);
|
|
191
|
+
}
|
|
192
|
+
|
|
179
193
|
void playbackProperties(long totalPlayed, long totalCovered) {
|
|
180
194
|
WritableMap event = Arguments.createMap();
|
|
181
195
|
event.putInt("totalPlayed", (int)totalPlayed);
|
|
@@ -183,6 +197,12 @@ class VdoEventEmitter {
|
|
|
183
197
|
receiveEvent(EVENT_PLAYBACK_PROPERTIES, event);
|
|
184
198
|
}
|
|
185
199
|
|
|
200
|
+
void isInitialPortrait() {
|
|
201
|
+
WritableMap event = Arguments.createMap();
|
|
202
|
+
event.putBoolean(EVENT_PROP_IS_INITIAL_PORTRAIT, true);
|
|
203
|
+
receiveEvent(EVENT_IS_INITIAL_PORTRAIT, event);
|
|
204
|
+
}
|
|
205
|
+
|
|
186
206
|
private void receiveEvent(@VdoEvent String type, WritableMap event) {
|
|
187
207
|
eventEmitter.receiveEvent(viewId, type, event);
|
|
188
208
|
}
|
|
@@ -26,7 +26,8 @@ public class VdocipherRnBridgePackage implements ReactPackage {
|
|
|
26
26
|
@Override
|
|
27
27
|
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
28
28
|
return Arrays.<ViewManager>asList(
|
|
29
|
-
new ReactVdoPlayerViewManager()
|
|
29
|
+
new ReactVdoPlayerViewManager(),
|
|
30
|
+
new ReactVdoPlayerUIViewManager()
|
|
30
31
|
);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:layout_width="match_parent"
|
|
4
|
+
android:layout_height="match_parent">
|
|
5
|
+
<fragment
|
|
6
|
+
android:name="com.vdocipher.aegis.ui.view.VdoPlayerUIFragment"
|
|
7
|
+
android:id="@+id/online_vdo_player_ui_fragment"
|
|
8
|
+
android:layout_width="match_parent"
|
|
9
|
+
android:layout_height="wrap_content"
|
|
10
|
+
android:layout_gravity="center"
|
|
11
|
+
android:keepScreenOn="true"/>
|
|
12
|
+
</FrameLayout>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:layout_width="match_parent"
|
|
4
|
+
android:layout_height="match_parent">
|
|
5
|
+
<fragment
|
|
6
|
+
android:name="com.vdocipher.aegis.player.VdoPlayerSupportFragment"
|
|
7
|
+
android:id="@+id/online_vdo_player_support_fragment"
|
|
8
|
+
android:layout_width="match_parent"
|
|
9
|
+
android:layout_height="wrap_content"
|
|
10
|
+
android:layout_gravity="center"
|
|
11
|
+
android:keepScreenOn="true"/>
|
|
12
|
+
</FrameLayout>
|
package/downloadMonitor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NativeEventEmitter
|
|
1
|
+
import { NativeEventEmitter } from 'react-native';
|
|
2
2
|
|
|
3
|
-
const eventEmitter = new NativeEventEmitter(
|
|
3
|
+
const eventEmitter = new NativeEventEmitter();
|
|
4
4
|
|
|
5
5
|
const nativeEvents = ['onQueued', 'onChanged', 'onCompleted', 'onFailed', 'onDeleted'];
|
|
6
6
|
|