Skip to content

Commit 85f88ce

Browse files
committed
fix: adStarted method in ios, pause in android
1 parent 686a97d commit 85f88ce

8 files changed

+20
-16
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -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 (ANDROID ONLY) | |
76+
| adStarted | Function | Indicates the IMA ad has started | |
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/src/main/java/com/matejdr/brightcoveimaplayer/BrightcoveIMAPlayerView.java

+10-12
Original file line numberDiff line numberDiff line change
@@ -329,22 +329,20 @@ public void stopPlayback() {
329329
}
330330

331331
public void pause() {
332-
if (this.brightcoveVideoView != null) {
333-
if (this.adsPlaying && this.googleIMAComponent != null) {
334-
this.googleIMAComponent.getVideoAdPlayer().pauseAd();
335-
} else if (this.playing) {
336-
this.brightcoveVideoView.pause();
337-
}
332+
if (this.adsPlaying && this.googleIMAComponent != null && this.googleIMAComponent.getVideoAdPlayer() != null) {
333+
// TODO upgrade to pauseAd(AdMediaInfo)
334+
this.googleIMAComponent.getVideoAdPlayer().pause();
335+
} else if (this.playing && this.brightcoveVideoView != null) {
336+
this.brightcoveVideoView.pause();
338337
}
339338
}
340339

341340
public void play() {
342-
if (this.brightcoveVideoView != null) {
343-
if (this.adsPlaying && this.googleIMAComponent != null) {
344-
this.googleIMAComponent.getVideoAdPlayer().resumeAd();
345-
} else {
346-
this.brightcoveVideoView.start();
347-
}
341+
if (this.adsPlaying && this.googleIMAComponent != null && this.googleIMAComponent.getVideoAdPlayer() != null) {
342+
// TODO upgrade to resumeAd(AdMediaInfo)
343+
this.googleIMAComponent.getVideoAdPlayer().resumeAd();
344+
} else if (this.brightcoveVideoView != null) {
345+
this.brightcoveVideoView.start();
348346
}
349347
}
350348

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void receiveCommand(BrightcoveIMAPlayerView view, int commandType, @Nulla
167167
public @Nullable
168168
Map<String, Object> getExportedCustomDirectEventTypeConstants() {
169169
Map<String, Object> map = new HashMap<>();
170-
map.put(AD_STARTED, (Object) MapBuilder.of("registrationName", "adStarted"));
170+
map.put(AD_STARTED, (Object) MapBuilder.of("registrationName", "onAdStarted"));
171171
map.put(EVENT_READY, (Object) MapBuilder.of("registrationName", "onReady"));
172172
map.put(EVENT_PLAY, (Object) MapBuilder.of("registrationName", "onPlay"));
173173
map.put(EVENT_PAUSE, (Object) MapBuilder.of("registrationName", "onPause"));

ios/BrightcoveIMAPlayerView.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
@property (nonatomic, copy) NSString *videoId;
3939
@property (nonatomic, copy) NSString *accountId;
4040
@property (nonatomic, copy) NSString *policyKey;
41+
@property (nonatomic, copy) RCTDirectEventBlock onAdStarted;
4142
@property (nonatomic, copy) RCTDirectEventBlock onReady;
4243
@property (nonatomic, copy) RCTDirectEventBlock onPlay;
4344
@property (nonatomic, copy) RCTDirectEventBlock onPause;

ios/BrightcoveIMAPlayerView.m

+4
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ - (void)playbackController:(id<BCOVPlaybackController>)controller playbackSessio
332332
if (self.onPause) {
333333
self.onPause(@{});
334334
}
335+
} else if (lifecycleEvent.eventType == kBCOVIMALifecycleEventAdsLoaderLoaded) {
336+
if (self.onAdStarted) {
337+
self.onAdStarted(@{});
338+
}
335339
} else if (lifecycleEvent.eventType == kBCOVPlaybackSessionLifecycleEventAdProgress) {
336340
// catches scroll away before ads start bug
337341
if (!_inViewPort) {

ios/BrightcoveIMAPlayerViewManager.m

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ - (dispatch_queue_t)methodQueue {
2727
RCT_EXPORT_VIEW_PROPERTY(bitRate, NSNumber);
2828
RCT_EXPORT_VIEW_PROPERTY(adVideoLoadTimeout, NSNumber);
2929
RCT_EXPORT_VIEW_PROPERTY(playbackRate, NSNumber);
30+
RCT_EXPORT_VIEW_PROPERTY(onAdStarted, RCTDirectEventBlock);
3031
RCT_EXPORT_VIEW_PROPERTY(onReady, RCTDirectEventBlock);
3132
RCT_EXPORT_VIEW_PROPERTY(onPlay, RCTDirectEventBlock);
3233
RCT_EXPORT_VIEW_PROPERTY(onPause, RCTDirectEventBlock);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-brightcove-ima-player",
3-
"version": "2.2.7",
3+
"version": "2.2.8",
44
"description": "React Native implementation of Brightcove Player native SDK",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

src/BrightcoveIMAPlayer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type BrightcoveIMAPlayerProps = ViewProps & {
5454
*/
5555
adVideoLoadTimeout?: number;
5656
playbackRate?: number;
57-
adStarted?: (
57+
onAdStarted?: (
5858
event: NativeSyntheticEvent<TBrightcoveIMAPlayerEventBase>
5959
) => void;
6060
onReady?: (

0 commit comments

Comments
 (0)