Skip to content

Commit 41b5c5d

Browse files
committed
fix: add adStarted event
1 parent 1668b45 commit 41b5c5d

7 files changed

+19
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +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 | |
7677
| onReady | Function | Indicates the video can be played back | |
7778
| onPlay | Function | Indicates the video playback starts | |
7879
| onPause | Function | Indicates the video is paused | |

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

+8
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ private void setup() {
106106
// Use a procedural abstraction to setup the Google IMA SDK via the plugin.
107107
setupGoogleIMA();
108108

109+
eventEmitter.on(EventType.AD_STARTED, new EventListener() {
110+
@Override
111+
public void processEvent(Event e) {
112+
WritableMap event = Arguments.createMap();
113+
ReactContext reactContext = (ReactContext) BrightcoveIMAPlayerView.this.getContext();
114+
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(BrightcoveIMAPlayerView.this.getId(), BrightcoveIMAPlayerViewManager.AD_STARTED, event);
115+
}
116+
});
109117
eventEmitter.on(EventType.VIDEO_SIZE_KNOWN, new EventListener() {
110118
@Override
111119
public void processEvent(Event e) {

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

+2
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 String AD_STARTED = "ad_started";
2526
public static final String EVENT_READY = "ready";
2627
public static final String EVENT_PLAY = "play";
2728
public static final String EVENT_PAUSE = "pause";
@@ -159,6 +160,7 @@ public void receiveCommand(BrightcoveIMAPlayerView view, int commandType, @Nulla
159160
public @Nullable
160161
Map<String, Object> getExportedCustomDirectEventTypeConstants() {
161162
Map<String, Object> map = new HashMap<>();
163+
map.put(AD_STARTED, (Object) MapBuilder.of("registrationName", "adStarted"));
162164
map.put(EVENT_READY, (Object) MapBuilder.of("registrationName", "onReady"));
163165
map.put(EVENT_PLAY, (Object) MapBuilder.of("registrationName", "onPlay"));
164166
map.put(EVENT_PAUSE, (Object) MapBuilder.of("registrationName", "onPause"));

ios/BrightcoveIMAPlayerView.m

+3
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ - (void)playbackController:(id<BCOVPlaybackController>)controller playbackSessio
347347
switch (adEvent.type)
348348
{
349349
case kIMAAdEvent_STARTED:
350+
if (self.adStarted) {
351+
self.adStarted(@{});
352+
}
350353
_adsPlaying = YES;
351354
break;
352355
case kIMAAdEvent_COMPLETE:

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(adStarted, 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.4",
3+
"version": "2.2.5",
44
"description": "React Native implementation of Brightcove Player native SDK",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

src/BrightcoveIMAPlayer.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ type BrightcoveIMAPlayerProps = ViewProps & {
5454
*/
5555
adVideoLoadTimeout?: number;
5656
playbackRate?: number;
57+
adStarted?: (
58+
event: NativeSyntheticEvent<TBrightcoveIMAPlayerEventBase>
59+
) => void;
5760
onReady?: (
5861
event: NativeSyntheticEvent<TBrightcoveIMAPlayerEventBase>
5962
) => void;

0 commit comments

Comments
 (0)