vdocipher-rn-bridge 1.10.2 → 1.12.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/VdoPlayerView.js CHANGED
@@ -3,10 +3,11 @@
3
3
  */
4
4
  import React, { Component, Fragment } from 'react';
5
5
  import PropTypes from 'prop-types';
6
- import { BackHandler} from 'react-native';
6
+ import { BackHandler, NativeModules} from 'react-native';
7
7
  import { ViewPropTypes } from 'deprecated-react-native-prop-types';
8
8
  import VdoPlayerSupportView from './VdoPlayerSupportView';
9
9
  import VdoPlayerUIView from './VdoPlayerUIView';
10
+ const { TrackSelection } = NativeModules;
10
11
 
11
12
  export default class VdoPlayerView extends Component {
12
13
 
@@ -58,6 +59,79 @@
58
59
  this._vdoPlayerView.getPlaybackProperties();
59
60
  }
60
61
  }
62
+
63
+ isAdaptive = async() => {
64
+ return new Promise(async(resolve) => { await TrackSelection.isAdaptive((isAdaptive) => {
65
+ resolve(isAdaptive);
66
+ });
67
+ });
68
+ }
69
+
70
+ getVideoQualities = async() => {
71
+ return new Promise(async(resolve) => { await TrackSelection.getVideoQualities((videoQualities) => {
72
+ resolve(videoQualities);
73
+ });
74
+ });
75
+ }
76
+
77
+ getSelectedVideoQuality = async() => {
78
+ return new Promise(async(resolve) => { await TrackSelection.getSelectedVideoQuality((selectedVideoQuality) => {
79
+ resolve(selectedVideoQuality);
80
+ });
81
+ });
82
+ }
83
+
84
+ setVideoQuality = videoQuality => {
85
+ if (this._vdoPlayerView) {
86
+ this._vdoPlayerView.setVideoQuality(videoQuality);
87
+ }
88
+ }
89
+
90
+ enableAdaptiveVideo = () => {
91
+ if (this._vdoPlayerView) {
92
+ this._vdoPlayerView.enableAdaptiveVideo();
93
+ }
94
+ }
95
+
96
+ getSelectedAudioQuality = async() => {
97
+ return new Promise(async(resolve) => { await TrackSelection.getSelectedAudioQuality((selectedAudioQuality) => {
98
+ resolve(selectedAudioQuality);
99
+ });
100
+ });
101
+ }
102
+
103
+ getCaptionLanguages = async() => {
104
+ return new Promise(async(resolve) => { await TrackSelection.getCaptionLanguages((captionLanguages) => {
105
+ resolve(captionLanguages);
106
+ });
107
+ });
108
+ }
109
+
110
+ getSelectedCaptionLanguage = async() => {
111
+ return new Promise(async(resolve) => { await TrackSelection.getSelectedCaptionLanguage((selectedCaptionLanguage) => {
112
+ resolve(selectedCaptionLanguage);
113
+ });
114
+ });
115
+ }
116
+
117
+ setCaptionLanguage = captionLanguage => {
118
+ if (this._vdoPlayerView) {
119
+ this._vdoPlayerView.setCaptionLanguage(captionLanguage);
120
+ }
121
+ }
122
+
123
+ disableCaptions = () => {
124
+ if (this._vdoPlayerView) {
125
+ this._vdoPlayerView.disableCaptions();
126
+ }
127
+ }
128
+
129
+ getDuration = async() => {
130
+ return new Promise(async(resolve) => { await TrackSelection.getDuration((duration) => {
131
+ resolve(duration);
132
+ });
133
+ });
134
+ }
61
135
 
62
136
  _onInitSuccess = (event) => {
63
137
  if (this.props.onInitializationSuccess) {
@@ -162,12 +236,12 @@
162
236
  isInitialPortrait: event.nativeEvent.isInitialPortrait
163
237
  });
164
238
  }
165
-
239
+
166
240
  _onPictureInPictureModeChanged = (event) => {
167
241
  if (this.props.onPictureInPictureModeChanged) {
168
- this.props.onPictureInPictureModeChanged(event);
242
+ this.props.onPictureInPictureModeChanged(event.nativeEvent);
169
243
  }
170
- }
244
+ }
171
245
 
172
246
  render() {
173
247
  return (
@@ -191,6 +265,7 @@
191
265
  onVdoEnterFullscreen={this._onEnterFullscreen}
192
266
  onVdoExitFullscreen={this._onExitFullscreen}
193
267
  onIsInitialPortrait={this._onIsInitialPortrait}
268
+ onVdoPictureInPictureModeChanged={this._onPictureInPictureModeChanged}
194
269
  {...this.props}
195
270
  />
196
271
  ) :
@@ -212,7 +287,6 @@
212
287
  onVdoEnterFullscreen={this._onEnterFullscreen}
213
288
  onVdoExitFullscreen={this._onExitFullscreen}
214
289
  onIsInitialPortrait={this._onIsInitialPortrait}
215
- onPictureInPictureModeChanged={this._onPictureInPictureModeChanged}
216
290
  {...this.props}
217
291
  />
218
292
  )
@@ -243,6 +317,7 @@
243
317
  onVdoEnterFullscreen: PropTypes.func,
244
318
  onVdoExitFullscreen: PropTypes.func,
245
319
  onIsInitialPortrait: PropTypes.func,
320
+ onVdoPictureInPictureModeChanged: PropTypes.func,
246
321
 
247
322
  /* Wrapper component public api */
248
323
  embedInfo: PropTypes.object,
@@ -18,8 +18,8 @@ apply plugin: 'com.android.library'
18
18
  // TODO read from package.json
19
19
  // "releaseVersionName" must be the same as "version" in package.json
20
20
  // "releaseVersionCode" must increment by 1 with every release
21
- def releaseVersionName = "1.10.2"
22
- def releaseVersionCode = 9
21
+ def releaseVersionName = "1.12.0"
22
+ def releaseVersionCode = 11
23
23
 
24
24
  android {
25
25
  compileSdkVersion 33
@@ -86,5 +86,5 @@ repositories {
86
86
  dependencies {
87
87
  compileOnly 'com.facebook.react:react-native:+'
88
88
  implementation 'androidx.appcompat:appcompat:1.3.1'
89
- implementation 'com.vdocipher.aegis:vdocipher-android:1.18.2'
89
+ implementation 'com.vdocipher.aegis:vdocipher-android:1.19.1'
90
90
  }
@@ -21,6 +21,8 @@ import com.vdocipher.aegis.player.PlayerHost;
21
21
  import com.vdocipher.aegis.player.VdoInitParams;
22
22
  import com.vdocipher.aegis.ui.view.VdoPlayerControlView;
23
23
  import com.vdocipher.aegis.ui.view.VdoPlayerUIFragment;
24
+ import android.os.Handler;
25
+ import android.os.Bundle;
24
26
 
25
27
 
26
28
  public class ReactVdoPlayerUIView extends FrameLayout implements LifecycleEventListener, Consumer<Configuration> {
@@ -40,19 +42,25 @@ public class ReactVdoPlayerUIView extends FrameLayout implements LifecycleEventL
40
42
  private VdoInitParams vdoParams;
41
43
  private AppCompatActivity activity;
42
44
 
45
+ private FragmentManager fragmentManager;
46
+
43
47
  public ReactVdoPlayerUIView(ThemedReactContext context) {
44
48
  super(context);
45
49
  themedReactContext = context;
46
50
  activity = (AppCompatActivity) themedReactContext.getCurrentActivity();
51
+ setKeepScreenOn(true);
47
52
 
48
53
  context.addLifecycleEventListener(this);
49
54
  activity.addOnConfigurationChangedListener(this);
50
55
 
51
56
  eventEmitter = new VdoEventEmitter(context);
52
57
 
53
- LayoutInflater.from(context).inflate(R.layout.activity_vdo_player_ui, this);
54
58
 
55
- vdoPlayerUIFragment = (VdoPlayerUIFragment) activity.getSupportFragmentManager().findFragmentById(R.id.online_vdo_player_ui_fragment);
59
+ vdoPlayerUIFragment = new VdoPlayerUIFragment();
60
+ Bundle bundle = new Bundle();
61
+ bundle.putBoolean("showControls", true);
62
+ vdoPlayerUIFragment.setArguments(bundle);
63
+ fragmentManager = this.activity.getSupportFragmentManager();
56
64
  initializePlayer();
57
65
 
58
66
  int orientation = getResources().getConfiguration().orientation;
@@ -64,9 +72,15 @@ public class ReactVdoPlayerUIView extends FrameLayout implements LifecycleEventL
64
72
 
65
73
  private void initializePlayer() {
66
74
  if (vdoPlayerUIFragment != null) {
67
- // initialize the playerFragment; a VdoPlayer instance will be received
68
- // in onInitializationSuccess() callback
69
- vdoPlayerUIFragment.initialize(initializationListener);
75
+ new Handler().postDelayed(() -> {
76
+ if (fragmentManager != null && !fragmentManager.isDestroyed()) {
77
+ fragmentManager.beginTransaction().replace(getId(), vdoPlayerUIFragment, VdoPlayerUIFragment.class.getName()).commitNow();
78
+ }
79
+ vdoPlayerControlView = vdoPlayerUIFragment.requireView().findViewById(R.id.vdo_player_control_view);
80
+ // initialize the playerFragment; a VdoPlayer instance will be received
81
+ // in onInitializationSuccess() callback
82
+ vdoPlayerUIFragment.initialize(initializationListener);
83
+ }, 200);
70
84
  }
71
85
  }
72
86
 
@@ -76,6 +90,13 @@ public class ReactVdoPlayerUIView extends FrameLayout implements LifecycleEventL
76
90
  */
77
91
  public void cleanUp() {
78
92
  themedReactContext.removeLifecycleEventListener(this);
93
+ if (vdoPlayer != null) {
94
+ vdoPlayer.stop();
95
+ }
96
+ if (fragmentManager != null && !fragmentManager.isDestroyed()) {
97
+ fragmentManager.beginTransaction().remove(fragmentManager.findFragmentById(vdoPlayerUIFragment.getId())).commitNow();
98
+ vdoPlayerUIFragment = null;
99
+ }
79
100
  }
80
101
 
81
102
  public void getPlaybackProperties() {
@@ -130,15 +151,18 @@ public class ReactVdoPlayerUIView extends FrameLayout implements LifecycleEventL
130
151
  protected void onAttachedToWindow() {
131
152
  Log.d(TAG, "onAttachedToWindow");
132
153
  super.onAttachedToWindow();
133
- vdoPlayerControlView = vdoPlayerUIFragment.requireView().findViewById(R.id.player_control_view);
154
+ if (playWhenReady) {
155
+ if (vdoPlayer != null) {
156
+ vdoPlayer.setPlayWhenReady(true);
157
+ }
158
+ }
134
159
  }
135
160
 
136
161
  @Override
137
162
  protected void onDetachedFromWindow() {
138
163
  Log.d(TAG, "onDetachedFromWindow");
139
- FragmentManager fragmentManager = this.activity.getSupportFragmentManager();
140
- if (fragmentManager != null && !fragmentManager.isDestroyed()) {
141
- fragmentManager.beginTransaction().remove(vdoPlayerUIFragment).commitNow();
164
+ if (vdoPlayer != null) {
165
+ vdoPlayer.setPlayWhenReady(false);
142
166
  }
143
167
  super.onDetachedFromWindow();
144
168
  }
@@ -1,6 +1,5 @@
1
1
  package com.vdocipher.rnbridge;
2
2
 
3
- import android.app.Activity;
4
3
  import android.os.Build;
5
4
  import android.util.Log;
6
5
  import android.view.View;
@@ -21,7 +20,7 @@ import com.vdocipher.aegis.player.PlayerHost;
21
20
  import com.vdocipher.aegis.player.PlayerHost.InitializationListener;
22
21
  import com.vdocipher.aegis.player.VdoPlayer.PlaybackEventListener;
23
22
  import com.vdocipher.aegis.player.VdoInitParams;
24
- import com.vdocipher.aegis.player.VdoPlayerSupportFragment;
23
+ import com.vdocipher.aegis.ui.view.VdoPlayerUIFragment;
25
24
  import android.media.AudioManager;
26
25
  import android.app.UiModeManager;
27
26
  import android.content.Context;
@@ -32,15 +31,25 @@ import android.support.v4.media.MediaMetadataCompat;
32
31
  import android.support.v4.media.session.MediaControllerCompat;
33
32
  import android.support.v4.media.session.MediaSessionCompat;
34
33
  import android.support.v4.media.session.PlaybackStateCompat;
35
-
36
- public class ReactVdoPlayerView extends FrameLayout implements InitializationListener,
37
- PlaybackEventListener, LifecycleEventListener {
34
+ import android.os.Handler;
35
+ import android.os.Bundle;
36
+
37
+ import android.os.Looper;
38
+ import com.facebook.react.bridge.Callback;
39
+ import static com.vdocipher.rnbridge.Utils.*;
40
+ import com.facebook.react.bridge.WritableArray;
41
+ import com.facebook.react.bridge.ReadableMap;
42
+ import com.facebook.react.bridge.WritableMap;
43
+ import com.facebook.react.bridge.Arguments;
44
+
45
+ public class ReactVdoPlayerView extends FrameLayout implements LifecycleEventListener {
38
46
  private static final String TAG = "ReactVdoPlayerView";
39
47
 
40
48
  private final ThemedReactContext themedReactContext;
41
- private VdoPlayerSupportFragment vdoPlayerFragment;
42
49
  private final VdoEventEmitter eventEmitter;
50
+ private VdoPlayerUIFragment vdoPlayerUIFragment;
43
51
  private AudioManager audioManager;
52
+ private FragmentManager fragmentManager;
44
53
 
45
54
  private VdoPlayer vdoPlayer;
46
55
 
@@ -62,18 +71,26 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
62
71
 
63
72
  private Consumer<PictureInPictureModeChangedInfo> pictureModeChangedInfoConsumer;
64
73
 
74
+ private Track[] availableTracks;
75
+ private Track[] selectedTracks;
76
+ private Handler mainHandler;
77
+
65
78
  public ReactVdoPlayerView(ThemedReactContext context) {
66
79
  super(context);
67
80
  context.addLifecycleEventListener(this);
68
81
  themedReactContext = context;
82
+ activity = (AppCompatActivity) themedReactContext.getCurrentActivity();
83
+ // Get a handler that can be used to post to the main thread
84
+ mainHandler = new Handler(Looper.getMainLooper());
85
+ setKeepScreenOn(true);
69
86
 
70
87
  eventEmitter = new VdoEventEmitter(context);
71
88
 
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);
76
-
89
+ vdoPlayerUIFragment = new VdoPlayerUIFragment();
90
+ Bundle bundle = new Bundle();
91
+ bundle.putBoolean("showControls", false);
92
+ vdoPlayerUIFragment.setArguments(bundle);
93
+ fragmentManager = activity.getSupportFragmentManager();
77
94
  initializePlayer();
78
95
 
79
96
  int orientation = getResources().getConfiguration().orientation;
@@ -86,10 +103,15 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
86
103
  }
87
104
 
88
105
  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);
106
+ if (vdoPlayerUIFragment != null) {
107
+ new Handler().postDelayed(() -> {
108
+ if (fragmentManager != null && !fragmentManager.isDestroyed()) {
109
+ fragmentManager.beginTransaction().replace(getId(), vdoPlayerUIFragment, "VdoPlayerUIFragmentRN").commitNow();
110
+ }
111
+ // initialize the playerFragment; a VdoPlayer instance will be received
112
+ // in onInitializationSuccess() callback
113
+ vdoPlayerUIFragment.initialize(initializationListener);
114
+ }, 200);
93
115
  }
94
116
  }
95
117
 
@@ -101,6 +123,13 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
101
123
  if (hasPictureInPictureSupport && pictureModeChangedInfoConsumer != null) {
102
124
  activity.removeOnPictureInPictureModeChangedListener(pictureModeChangedInfoConsumer);
103
125
  }
126
+ if (vdoPlayer != null) {
127
+ vdoPlayer.stop();
128
+ }
129
+ if (fragmentManager != null && !fragmentManager.isDestroyed()) {
130
+ fragmentManager.beginTransaction().remove(fragmentManager.findFragmentById(vdoPlayerUIFragment.getId())).commitNow();
131
+ vdoPlayerUIFragment = null;
132
+ }
104
133
  }
105
134
 
106
135
  public boolean setFullscreen(boolean enterFullscreen) {
@@ -158,7 +187,7 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
158
187
  }
159
188
 
160
189
  public void setPlaybackSpeed(float playbackSpeed) {
161
- pendingPlaybackSpeed = playbackSpeed;
190
+ this.pendingPlaybackSpeed = playbackSpeed;
162
191
  if (vdoPlayer != null) {
163
192
  vdoPlayer.setPlaybackSpeed(playbackSpeed);
164
193
  }
@@ -258,6 +287,102 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
258
287
  }
259
288
  }
260
289
 
290
+ public void isAdaptive(Callback callback) {
291
+
292
+ if (vdoPlayer != null) {
293
+ mainHandler.post(() -> {
294
+ boolean isAdaptive = vdoPlayer.isAdaptive();
295
+ callback.invoke(isAdaptive);
296
+ });
297
+ } else {
298
+ callback.invoke(false);
299
+ }
300
+ }
301
+
302
+ public void getVideoQualities(Callback callback) {
303
+ WritableArray availableVideoQualities = Arguments.createArray();
304
+ if (this.availableTracks != null) {
305
+ availableVideoQualities = makeAvailableTrackMapArray(this.availableTracks, Track.TYPE_VIDEO);
306
+ }
307
+ callback.invoke(availableVideoQualities);
308
+ }
309
+
310
+ public void getSelectedVideoQuality(Callback callback) {
311
+ WritableMap selectedVideoQuality = Arguments.createMap();
312
+ if (this.selectedTracks != null) {
313
+ selectedVideoQuality = makeSelectedVideoTrackMap(this.selectedTracks);
314
+ }
315
+ callback.invoke(selectedVideoQuality);
316
+ }
317
+
318
+ public void getSelectedAudioQuality(Callback callback) {
319
+ WritableMap selectedAudioQuality = Arguments.createMap();
320
+ if (this.selectedTracks != null) {
321
+ selectedAudioQuality = makeSelectedAudioTrackMap(this.selectedTracks);
322
+ }
323
+ callback.invoke(selectedAudioQuality);
324
+ }
325
+
326
+ public void getSelectedCaptionLanguage(Callback callback) {
327
+ WritableMap selectedCaptionLanguage = Arguments.createMap();
328
+ if (this.selectedTracks != null) {
329
+ selectedCaptionLanguage = makeSelectedCaptionTrackMap(this.selectedTracks);
330
+ }
331
+ callback.invoke(selectedCaptionLanguage);
332
+ }
333
+
334
+ public void setSelectedTrack(ReadableMap selectedTrackMap) {
335
+ Track selectedTrack = makeTrack(selectedTrackMap, availableTracks);
336
+
337
+ if (vdoPlayer != null && selectedTrack != null) {
338
+ mainHandler.post(() -> {
339
+ vdoPlayer.setSelectedTracks(new Track[]{selectedTrack});
340
+ });
341
+ }
342
+ }
343
+
344
+ public void enableAdaptiveVideo() {
345
+ Track selectedTrack = Track.SET_ADAPTIVE;
346
+
347
+ if (vdoPlayer != null) {
348
+ mainHandler.post(() -> {
349
+ vdoPlayer.setSelectedTracks(new Track[]{selectedTrack});
350
+ });
351
+ }
352
+ }
353
+
354
+ public void getCaptionLanguages(Callback callback) {
355
+ WritableArray availableCaptionLanguages = Arguments.createArray();
356
+ if (this.availableTracks != null) {
357
+ availableCaptionLanguages = makeAvailableTrackMapArray(this.availableTracks, Track.TYPE_CAPTIONS);
358
+ }
359
+ callback.invoke(availableCaptionLanguages);
360
+ }
361
+
362
+ public void disableCaptions() {
363
+ Track selectedTrack = Track.DISABLE_CAPTIONS;
364
+
365
+ if (vdoPlayer != null) {
366
+ mainHandler.post(() -> {
367
+ vdoPlayer.setSelectedTracks(new Track[]{selectedTrack});
368
+ });
369
+ }
370
+ }
371
+
372
+ public void getDuration(Callback callback) {
373
+
374
+ if (vdoPlayer != null) {
375
+ mainHandler.post(() -> {
376
+ double videoDuration = vdoPlayer.getDuration();
377
+ WritableMap videoDurationMap = Arguments.createMap();
378
+ videoDurationMap.putDouble("duration", videoDuration);
379
+ callback.invoke(videoDurationMap);
380
+ });
381
+ } else {
382
+ callback.invoke(0);
383
+ }
384
+ }
385
+
261
386
  @Override
262
387
  public void setId(int id) {
263
388
  super.setId(id);
@@ -273,14 +398,18 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
273
398
  protected void onAttachedToWindow() {
274
399
  Log.d(TAG, "onAttachedToWindow");
275
400
  super.onAttachedToWindow();
401
+ if (playWhenReady) {
402
+ if (vdoPlayer != null) {
403
+ vdoPlayer.setPlayWhenReady(true);
404
+ }
405
+ }
276
406
  }
277
407
 
278
408
  @Override
279
409
  protected void onDetachedFromWindow() {
280
410
  Log.d(TAG, "onDetachedFromWindow");
281
- FragmentManager fragmentManager = activity.getSupportFragmentManager();
282
- if (fragmentManager != null && !fragmentManager.isDestroyed()) {
283
- fragmentManager.beginTransaction().remove(vdoPlayerFragment).commitNow();
411
+ if (vdoPlayer != null) {
412
+ vdoPlayer.setPlayWhenReady(false);
284
413
  }
285
414
  super.onDetachedFromWindow();
286
415
  }
@@ -304,14 +433,30 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
304
433
  // already unregistered as a lifecycle listener
305
434
  }
306
435
 
436
+ @Override
437
+ public void requestLayout() {
438
+ super.requestLayout();
439
+ post(measureAndLayout);
440
+ }
441
+
442
+ private final Runnable measureAndLayout = () -> {
443
+ measure(
444
+ MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
445
+ MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
446
+ layout(getLeft(), getTop(), getRight(), getBottom());
447
+ };
448
+
307
449
 
308
450
  // InitializationListener impl
309
451
 
452
+ PlayerHost.InitializationListener initializationListener = new PlayerHost.InitializationListener() {
310
453
  @Override
311
- public void onInitializationSuccess(PlayerHost playerHost, VdoPlayer vdoPlayer, boolean restored) {
454
+ public void onInitializationSuccess(PlayerHost playerHost, VdoPlayer player, boolean restored) {
312
455
  Log.d(TAG, "init success");
313
- this.vdoPlayer = vdoPlayer;
314
- vdoPlayer.addPlaybackEventListener(this);
456
+ vdoPlayer = player;
457
+ availableTracks = vdoPlayer.getAvailableTracks();
458
+ selectedTracks = vdoPlayer.getSelectedTracks();
459
+ vdoPlayer.addPlaybackEventListener(playbackListener);
315
460
  eventEmitter.initSuccess(restored);
316
461
 
317
462
  // load pending params
@@ -332,6 +477,8 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
332
477
  eventEmitter.initFailure(errorDescription);
333
478
  }
334
479
 
480
+ };
481
+
335
482
  public void load(VdoInitParams params) {
336
483
  if (vdoPlayer != null && params != null) {
337
484
  vdoPlayer.load(params);
@@ -340,31 +487,6 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
340
487
  }
341
488
  }
342
489
 
343
- // PlaybackEventListener impl
344
-
345
- @Override
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
- }
365
- eventEmitter.playerStateChanged(playWhenReady, playerState);
366
- }
367
-
368
490
  private boolean requestAudioFocus(AudioManager audioManager) {
369
491
  return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == audioManager.requestAudioFocus(audioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
370
492
  }
@@ -393,6 +515,32 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
393
515
  }
394
516
  };
395
517
 
518
+ // PlaybackEventListener impl
519
+
520
+ private final VdoPlayer.PlaybackEventListener playbackListener = new VdoPlayer.PlaybackEventListener() {
521
+ @Override
522
+ public void onPlayerStateChanged(boolean playWhenReady, int playerState) {
523
+ boolean playing = playerState != VdoPlayer.STATE_IDLE && playerState != VdoPlayer.STATE_ENDED && playWhenReady;
524
+
525
+ // We are playing the video now. Update the media session state and the PiP
526
+ // window will update the actions.
527
+
528
+ if (hasPictureInPictureSupport) {
529
+ updatePlaybackState(playing ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED, vdoPlayer.getCurrentTime(), vdoPlayer.getPlaybackSpeed());
530
+ }
531
+
532
+ if (playing) {
533
+ //Request audio focus and notify other players to stop playback.
534
+ if (!requestAudioFocus(audioManager)) {
535
+ Log.i(TAG, "Audio focus not granted");
536
+ }
537
+ } else if (playerState == VdoPlayer.STATE_ENDED) {
538
+ // Abandon audio focus when playback complete
539
+ audioManager.abandonAudioFocus(audioFocusChangeListener);
540
+ }
541
+ eventEmitter.playerStateChanged(playWhenReady, playerState);
542
+ }
543
+
396
544
  @Override
397
545
  public void onSeekTo(long timeMs) {
398
546
  eventEmitter.seekTo(timeMs);
@@ -444,7 +592,10 @@ public class ReactVdoPlayerView extends FrameLayout implements InitializationLis
444
592
  }
445
593
 
446
594
  @Override
447
- public void onTracksChanged(Track[] availableTracks, Track[] selectedTracks) {
595
+ public void onTracksChanged(Track[] tracksAvailable, Track[] tracksSelected) {
596
+ availableTracks = tracksAvailable;
597
+ selectedTracks = tracksSelected;
448
598
  eventEmitter.tracksChanged(availableTracks, selectedTracks);
449
599
  }
600
+ };
450
601
  }
@@ -8,18 +8,23 @@ import com.facebook.react.uimanager.ThemedReactContext;
8
8
  import com.facebook.react.uimanager.ViewGroupManager;
9
9
  import com.facebook.react.uimanager.annotations.ReactProp;
10
10
  import com.vdocipher.aegis.player.VdoInitParams;
11
+ import com.vdocipher.aegis.media.Track;
11
12
 
12
13
  import java.util.Map;
13
14
 
14
15
  import javax.annotation.Nullable;
15
16
 
16
17
  import static com.vdocipher.rnbridge.Utils.getTechOverride;
18
+ import com.facebook.react.bridge.ReadableMap;
17
19
 
18
20
  public class ReactVdoPlayerViewManager extends ViewGroupManager<ReactVdoPlayerView> {
19
21
  private static final String TAG = "ReactVdoPlayerViewMngr";
20
22
 
21
23
  private static final String REACT_CLASS = "RCTVdoPlayerView";
22
24
 
25
+ private ReactVdoPlayerView playerView;
26
+ private Callback callback;
27
+
23
28
  @Override
24
29
  public String getName() {
25
30
  return REACT_CLASS;
@@ -27,11 +32,16 @@ public class ReactVdoPlayerViewManager extends ViewGroupManager<ReactVdoPlayerVi
27
32
 
28
33
  @Override
29
34
  public ReactVdoPlayerView createViewInstance(ThemedReactContext context) {
30
- ReactVdoPlayerView playerView = new ReactVdoPlayerView(context);
35
+ playerView = new ReactVdoPlayerView(context);
31
36
  Log.d(TAG, "created " + playerView.toString());
37
+ callback.onVideoPlayerViewInitialised(playerView);
32
38
  return playerView;
33
39
  }
34
40
 
41
+ public void setCallback(Callback callback) {
42
+ this.callback = callback;
43
+ }
44
+
35
45
  @Nullable
36
46
  @Override
37
47
  public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
@@ -142,4 +152,29 @@ public class ReactVdoPlayerViewManager extends ViewGroupManager<ReactVdoPlayerVi
142
152
  public void getPlaybackProperties(ReactVdoPlayerView vdoPlayerView, int ref) {
143
153
  vdoPlayerView.getPlaybackProperties();
144
154
  }
155
+
156
+ @ReactProp(name = "videoQuality")
157
+ public void setVideoQuality(ReactVdoPlayerView vdoPlayerView, ReadableMap videoQuality) {
158
+ vdoPlayerView.setSelectedTrack(videoQuality);
159
+ }
160
+
161
+ @ReactProp(name = "adaptiveVideo")
162
+ public void enableAdaptiveVideo(ReactVdoPlayerView vdoPlayerView, int ref) {
163
+ vdoPlayerView.enableAdaptiveVideo();
164
+ }
165
+
166
+ @ReactProp(name = "captionLanguage")
167
+ public void setCaptionLanguage(ReactVdoPlayerView vdoPlayerView, ReadableMap captionLanguage) {
168
+ vdoPlayerView.setSelectedTrack(captionLanguage);
169
+ }
170
+
171
+ @ReactProp(name = "disableCaptions")
172
+ public void disableCaptions(ReactVdoPlayerView vdoPlayerView, int ref) {
173
+ vdoPlayerView.disableCaptions();
174
+ }
175
+
176
+ public interface Callback {
177
+ void onVideoPlayerViewInitialised(ReactVdoPlayerView vdoPlayerView);
178
+ }
179
+
145
180
  }