Skip to content

Commit

Permalink
fix: add adStarted event
Browse files Browse the repository at this point in the history
  • Loading branch information
aleccolville committed Jun 15, 2022
1 parent 1668b45 commit 41b5c5d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import { BrightcoveIMAPlayer } from "react-native-brightcove-ima-player";
| adVideoLoadTimeout | number | Set the amount of milliseconds for video to load. Default is `3000` | |
| playbackRate | number | Set playback speed scale. Default is `1` | |
| disableDefaultControl | boolean | Disable default player control. Set `true` when you implement own video controller. | |
| adStarted | Function | Indicates the IMA ad has started | |
| onReady | Function | Indicates the video can be played back | |
| onPlay | Function | Indicates the video playback starts | |
| onPause | Function | Indicates the video is paused | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ private void setup() {
// Use a procedural abstraction to setup the Google IMA SDK via the plugin.
setupGoogleIMA();

eventEmitter.on(EventType.AD_STARTED, new EventListener() {
@Override
public void processEvent(Event e) {
WritableMap event = Arguments.createMap();
ReactContext reactContext = (ReactContext) BrightcoveIMAPlayerView.this.getContext();
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(BrightcoveIMAPlayerView.this.getId(), BrightcoveIMAPlayerViewManager.AD_STARTED, event);
}
});
eventEmitter.on(EventType.VIDEO_SIZE_KNOWN, new EventListener() {
@Override
public void processEvent(Event e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class BrightcoveIMAPlayerViewManager extends SimpleViewManager<Brightcove
public static final int COMMAND_PAUSE = 3;
public static final int COMMAND_STOP_PLAYBACK = 4;
public static final int COMMAND_TOGGLE_FULLSCREEN = 5;
public static final String AD_STARTED = "ad_started";
public static final String EVENT_READY = "ready";
public static final String EVENT_PLAY = "play";
public static final String EVENT_PAUSE = "pause";
Expand Down Expand Up @@ -159,6 +160,7 @@ public void receiveCommand(BrightcoveIMAPlayerView view, int commandType, @Nulla
public @Nullable
Map<String, Object> getExportedCustomDirectEventTypeConstants() {
Map<String, Object> map = new HashMap<>();
map.put(AD_STARTED, (Object) MapBuilder.of("registrationName", "adStarted"));
map.put(EVENT_READY, (Object) MapBuilder.of("registrationName", "onReady"));
map.put(EVENT_PLAY, (Object) MapBuilder.of("registrationName", "onPlay"));
map.put(EVENT_PAUSE, (Object) MapBuilder.of("registrationName", "onPause"));
Expand Down
3 changes: 3 additions & 0 deletions ios/BrightcoveIMAPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ - (void)playbackController:(id<BCOVPlaybackController>)controller playbackSessio
switch (adEvent.type)
{
case kIMAAdEvent_STARTED:
if (self.adStarted) {
self.adStarted(@{});
}
_adsPlaying = YES;
break;
case kIMAAdEvent_COMPLETE:
Expand Down
1 change: 1 addition & 0 deletions ios/BrightcoveIMAPlayerViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ - (dispatch_queue_t)methodQueue {
RCT_EXPORT_VIEW_PROPERTY(bitRate, NSNumber);
RCT_EXPORT_VIEW_PROPERTY(adVideoLoadTimeout, NSNumber);
RCT_EXPORT_VIEW_PROPERTY(playbackRate, NSNumber);
RCT_EXPORT_VIEW_PROPERTY(adStarted, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onReady, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onPlay, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onPause, RCTDirectEventBlock);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-brightcove-ima-player",
"version": "2.2.4",
"version": "2.2.5",
"description": "React Native implementation of Brightcove Player native SDK",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
3 changes: 3 additions & 0 deletions src/BrightcoveIMAPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ type BrightcoveIMAPlayerProps = ViewProps & {
*/
adVideoLoadTimeout?: number;
playbackRate?: number;
adStarted?: (
event: NativeSyntheticEvent<TBrightcoveIMAPlayerEventBase>
) => void;
onReady?: (
event: NativeSyntheticEvent<TBrightcoveIMAPlayerEventBase>
) => void;
Expand Down

0 comments on commit 41b5c5d

Please sign in to comment.