Skip to content

Commit 686a97d

Browse files
committed
inViewPort addition
1 parent accd64c commit 686a97d

9 files changed

+113
-77
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ React Native implementation of Brightcove Player native SDK video player.
88

99
- Minimum Required version of iOS is 11
1010
- iOS Brightcove-Player-IMA 6.10.5
11-
- com.brightcove.player:android-ima-plugin 6.18.4
11+
- com.brightcove.player:android-ima-plugin 6.18.6
1212

1313
## Installation
1414

@@ -73,7 +73,7 @@ import { BrightcoveIMAPlayer } from "react-native-brightcove-ima-player";
7373
| adVideoLoadTimeout | number | Set the amount of milliseconds for video to load. Default is `3000` | |
7474
| playbackRate | number | Set playback speed scale. Default is `1` | |
7575
| disableDefaultControl | boolean | Disable default player control. Set `true` when you implement own video controller. | |
76-
| adStarted | Function | Indicates the IMA ad has started | |
76+
| adStarted | Function | Indicates the IMA ad has started (ANDROID ONLY) | |
7777
| onReady | Function | Indicates the video can be played back | |
7878
| onPlay | Function | Indicates the video playback starts | |
7979
| onPause | Function | Indicates the video is paused | |

android/constants.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
project.ext {
2-
BRIGHTCOVE_VERSION = '6.18.4'
2+
BRIGHTCOVE_VERSION = '6.18.6'
33
PLAY_SERVICES_VERSION = '20.3.0'
44
GOOGLE_IMA_SDK_VERSION = '3.21.1'
55
ANDROIDX_LEGACY_SUPPORT_V4 = '1.0.0'

android/src/main/java/com/matejdr/brightcoveimaplayer/BrightcoveIMAPlayerView.java

+25-18
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class BrightcoveIMAPlayerView extends RelativeLayout implements Lifecycle
6363
private boolean autoPlay = true;
6464
private boolean playing = false;
6565
private boolean adsPlaying = false;
66+
private boolean inViewPort = true;
6667
private boolean disableDefaultControl = false;
6768
private int bitRate = 0;
6869
private int adVideoLoadTimeout = 3000;
@@ -211,13 +212,15 @@ public void processEvent(Event e) {
211212
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(BrightcoveIMAPlayerView.this.getId(), BrightcoveIMAPlayerViewManager.EVENT_UPDATE_BUFFER_PROGRESS, event);
212213
}
213214
});
215+
214216
}
215217

216218
public void setSettings(ReadableMap settings) {
217219
this.settings = settings;
218-
if (settings != null && settings.hasKey("autoPlay")) {
219-
this.autoPlay = settings.getBoolean("autoPlay");
220-
}
220+
// disabling autoPlay coming from settings object
221+
// if (settings != null && settings.hasKey("autoPlay")) {
222+
// this.autoPlay = settings.getBoolean("autoPlay");
223+
// }
221224
}
222225

223226
public void setPolicyKey(String policyKey) {
@@ -277,6 +280,16 @@ public void toggleFullscreen(boolean isFullscreen) {
277280
}
278281
}
279282

283+
public void toggleInViewPort(boolean inViewPort) {
284+
if (inViewPort) {
285+
this.inViewPort = true;
286+
} else {
287+
this.inViewPort = false;
288+
// need to pause here also - (differs from IOS behaviour)
289+
this.pause();
290+
}
291+
}
292+
280293
public void setVolume(float volume) {
281294
Map<String, Object> details = new HashMap<>();
282295
details.put(Event.VOLUME, volume);
@@ -319,7 +332,7 @@ public void pause() {
319332
if (this.brightcoveVideoView != null) {
320333
if (this.adsPlaying && this.googleIMAComponent != null) {
321334
this.googleIMAComponent.getVideoAdPlayer().pauseAd();
322-
} else {
335+
} else if (this.playing) {
323336
this.brightcoveVideoView.pause();
324337
}
325338
}
@@ -328,7 +341,6 @@ public void pause() {
328341
public void play() {
329342
if (this.brightcoveVideoView != null) {
330343
if (this.adsPlaying && this.googleIMAComponent != null) {
331-
//this.brightcoveVideoView.pause();
332344
this.googleIMAComponent.getVideoAdPlayer().resumeAd();
333345
} else {
334346
this.brightcoveVideoView.start();
@@ -400,7 +412,7 @@ private void fixVideoLayout() {
400412
}
401413

402414
/*
403-
This methods show how to the the Google IMA AdsManager, get the cue points and add the markers
415+
This methods show how to get the Google IMA AdsManager, get the cue points and add the markers
404416
to the Brightcove Seek Bar.
405417
*/
406418
private void setupAdMarkers(BaseVideoView videoView) {
@@ -416,7 +428,6 @@ private void setupAdMarkers(BaseVideoView videoView) {
416428
// If cuepoint is negative it means it is a POST ROLL.
417429
int markerTime = cuepoint < 0 ? brightcoveSeekBar.getMax() : (int) (cuepoint * DateUtils.SECOND_IN_MILLIS);
418430
mediaController.getBrightcoveSeekBar().addMarker(markerTime);
419-
420431
}
421432
});
422433
videoView.setMediaController(mediaController);
@@ -444,9 +455,7 @@ private void setupGoogleIMA() {
444455
adsPlaying = false;
445456
});
446457

447-
// Set up a listener for initializing AdsRequests. The Google
448-
// IMA plugin emits an ad request event as a result of
449-
// initializeAdsRequests() being called.
458+
// Set up a listener for initializing AdsRequests.
450459
eventEmitter.on(GoogleIMAEventType.ADS_REQUEST_FOR_VIDEO, event -> {
451460
String IMAUrl = settings != null && settings.hasKey("IMAUrl") ?
452461
settings.getString("IMAUrl") : "";
@@ -481,18 +490,16 @@ private void setupGoogleIMA() {
481490

482491
@Override
483492
public void onHostResume() {
484-
if (this.adsPlaying && this.googleIMAComponent != null && googleIMAComponent.getVideoAdPlayer() != null) {
485-
this.googleIMAComponent.getVideoAdPlayer().playAd();
486-
} else if (this.playing && this.brightcoveVideoView != null) {
487-
this.brightcoveVideoView.start();
488-
}
493+
// handleAppStateDidChange active
494+
this.pause();
495+
this.toggleInViewPort(true);
489496
}
490497

491498
@Override
492499
public void onHostPause() {
493-
if (this.adsPlaying && this.googleIMAComponent != null && googleIMAComponent.getVideoAdPlayer() != null) {
494-
googleIMAComponent.getVideoAdPlayer().pause();
495-
}
500+
// handleAppStateDidChange background
501+
this.pause();
502+
this.toggleInViewPort(false);
496503
}
497504

498505
@Override

android/src/main/java/com/matejdr/brightcoveimaplayer/BrightcoveIMAPlayerViewManager.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class BrightcoveIMAPlayerViewManager extends SimpleViewManager<Brightcove
2222
public static final int COMMAND_PAUSE = 3;
2323
public static final int COMMAND_STOP_PLAYBACK = 4;
2424
public static final int COMMAND_TOGGLE_FULLSCREEN = 5;
25+
public static final int COMMAND_TOGGLE_IN_VIEW_PORT = 6;
2526
public static final String AD_STARTED = "ad_started";
2627
public static final String EVENT_READY = "ready";
2728
public static final String EVENT_PLAY = "play";
@@ -124,7 +125,9 @@ public Map<String, Integer> getCommandsMap() {
124125
"stopPlayback",
125126
COMMAND_STOP_PLAYBACK,
126127
"toggleFullscreen",
127-
COMMAND_TOGGLE_FULLSCREEN
128+
COMMAND_TOGGLE_FULLSCREEN,
129+
"toggleInViewPort",
130+
COMMAND_TOGGLE_IN_VIEW_PORT
128131
);
129132
}
130133

@@ -153,6 +156,10 @@ public void receiveCommand(BrightcoveIMAPlayerView view, int commandType, @Nulla
153156
view.toggleFullscreen((boolean) (args.getBoolean(0)));
154157
return;
155158
}
159+
case COMMAND_TOGGLE_IN_VIEW_PORT: {
160+
view.toggleInViewPort((boolean) (args.getBoolean(0)));
161+
return;
162+
}
156163
}
157164
}
158165

ios/BrightcoveIMAPlayerView.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
@property (nonatomic) float targetPlaybackRate;
3333
@property (nonatomic) BOOL playbackServiceDirty;
3434
@property (nonatomic) NSTimeInterval currentVideoDuration;
35+
@property (nonatomic) BOOL inViewPort;
3536

3637
@property (nonatomic, copy) NSDictionary *settings;
3738
@property (nonatomic, copy) NSString *videoId;
3839
@property (nonatomic, copy) NSString *accountId;
3940
@property (nonatomic, copy) NSString *policyKey;
40-
@property (nonatomic, copy) RCTDirectEventBlock adStarted;
4141
@property (nonatomic, copy) RCTDirectEventBlock onReady;
4242
@property (nonatomic, copy) RCTDirectEventBlock onPlay;
4343
@property (nonatomic, copy) RCTDirectEventBlock onPause;
@@ -51,6 +51,7 @@
5151
-(void) setupWithSettings:(NSString*)settings;
5252
-(void) seekTo:(NSNumber *)time;
5353
-(void) toggleFullscreen:(BOOL)isFullscreen;
54+
-(void) toggleInViewPort:(BOOL)inViewPort;
5455
-(void) pause;
5556
-(void) play;
5657
-(void) stopPlayback;

0 commit comments

Comments
 (0)