From 1fbd9bda753e24ef3575c69093b0fc80db3812da Mon Sep 17 00:00:00 2001 From: Adrien Thiery Date: Thu, 4 Jan 2018 16:33:38 +0100 Subject: [PATCH] Enabled iOS preroll playing (problems: Video not showing and link not opening Safari) --- .../brightcove-player.defaults.js | 1 + .../brightcove-player.native.js | 1 + .../brightcove-player.proptypes.js | 1 + .../RNTBrightcove.xcodeproj/project.pbxproj | 4 ++ .../ios/RNTBrightcove/RNTBrightcoveManager.m | 1 + .../ios/RNTBrightcove/RNTBrightcoveView.h | 3 ++ .../ios/RNTBrightcove/RNTBrightcoveView.m | 38 +++++++++++++++---- 7 files changed, 42 insertions(+), 7 deletions(-) diff --git a/packages/brightcove-video/brightcove-player.defaults.js b/packages/brightcove-video/brightcove-player.defaults.js index ecf7c347d3f..e68e02f838c 100644 --- a/packages/brightcove-video/brightcove-player.defaults.js +++ b/packages/brightcove-video/brightcove-player.defaults.js @@ -2,6 +2,7 @@ export default { width: 320, height: 180, playerId: "default", + vastTag: null, onError: () => {}, onPlay: () => {}, onPause: () => {}, diff --git a/packages/brightcove-video/brightcove-player.native.js b/packages/brightcove-video/brightcove-player.native.js index f508cc37a03..e7adeee119f 100644 --- a/packages/brightcove-video/brightcove-player.native.js +++ b/packages/brightcove-video/brightcove-player.native.js @@ -138,6 +138,7 @@ class BrightcoveVideo extends Component { zIndex: this.props.zIndex }} policyKey={this.props.policyKey} + vastTag={this.props.vastTag} accountId={this.props.accountId} videoId={this.props.videoId} autoplay={this.props.autoplay} diff --git a/packages/brightcove-video/brightcove-player.proptypes.js b/packages/brightcove-video/brightcove-player.proptypes.js index 010e987d5ab..1a181789cf1 100644 --- a/packages/brightcove-video/brightcove-player.proptypes.js +++ b/packages/brightcove-video/brightcove-player.proptypes.js @@ -8,6 +8,7 @@ const numberOrString = PropTypes.oneOfType([ export default { videoId: PropTypes.string.isRequired, accountId: PropTypes.string.isRequired, + vastTag: PropTypes.string.isRequired, policyKey: PropTypes.string, playerId: PropTypes.string, width: numberOrString, diff --git a/packages/brightcove-video/ios/RNTBrightcove.xcodeproj/project.pbxproj b/packages/brightcove-video/ios/RNTBrightcove.xcodeproj/project.pbxproj index b6a3acca289..a8fd1cc34dc 100644 --- a/packages/brightcove-video/ios/RNTBrightcove.xcodeproj/project.pbxproj +++ b/packages/brightcove-video/ios/RNTBrightcove.xcodeproj/project.pbxproj @@ -284,6 +284,8 @@ "$(SRCROOT)/../../../../ios/Pods/Headers/Public/Brightcove-Player-Core", "$(SRCROOT)/../../../../React/**", "$(SRCROOT)/../../../react-native/React/**", + "$(SRCROOT)/../../../../ios/Pods/Headers/Public/Brightcove-Player-IMA", + "$(SRCROOT)/../../../../ios/Pods/Headers/Public/GoogleAds-IMA-iOS-SDK", ); LIBRARY_SEARCH_PATHS = "$(inherited)"; OTHER_LDFLAGS = "-ObjC"; @@ -309,6 +311,8 @@ "$(SRCROOT)/../../../../ios/Pods/Headers/Public/Brightcove-Player-Core", "$(SRCROOT)/../../../../React/**", "$(SRCROOT)/../../../react-native/React/**", + "$(SRCROOT)/../../../../ios/Pods/Headers/Public/Brightcove-Player-IMA", + "$(SRCROOT)/../../../../ios/Pods/Headers/Public/GoogleAds-IMA-iOS-SDK", ); LIBRARY_SEARCH_PATHS = "$(inherited)"; OTHER_LDFLAGS = "-ObjC"; diff --git a/packages/brightcove-video/ios/RNTBrightcove/RNTBrightcoveManager.m b/packages/brightcove-video/ios/RNTBrightcove/RNTBrightcoveManager.m index 7eba4738c12..9d9d1347900 100644 --- a/packages/brightcove-video/ios/RNTBrightcove/RNTBrightcoveManager.m +++ b/packages/brightcove-video/ios/RNTBrightcove/RNTBrightcoveManager.m @@ -6,6 +6,7 @@ @implementation RNTBrightcoveManager RCT_EXPORT_MODULE(); +RCT_EXPORT_VIEW_PROPERTY(vastTag, NSString); RCT_EXPORT_VIEW_PROPERTY(policyKey, NSString); RCT_EXPORT_VIEW_PROPERTY(accountId, NSString); RCT_EXPORT_VIEW_PROPERTY(videoId, NSString); diff --git a/packages/brightcove-video/ios/RNTBrightcove/RNTBrightcoveView.h b/packages/brightcove-video/ios/RNTBrightcove/RNTBrightcoveView.h index 6ff958febae..a782b522609 100644 --- a/packages/brightcove-video/ios/RNTBrightcove/RNTBrightcoveView.h +++ b/packages/brightcove-video/ios/RNTBrightcove/RNTBrightcoveView.h @@ -2,12 +2,15 @@ #import #import #import +#import +#import @class RCTEventDispatcher; @interface RNTBrightcoveView : UIView @property (nonatomic, copy) NSString *policyKey; +@property (nonatomic, copy) NSString *vastTag; @property (nonatomic, copy) NSString *accountId; @property (nonatomic, copy) NSString *videoId; @property (nonatomic, assign) BOOL autoplay; diff --git a/packages/brightcove-video/ios/RNTBrightcove/RNTBrightcoveView.m b/packages/brightcove-video/ios/RNTBrightcove/RNTBrightcoveView.m index 2c8f9cd2224..d46517ff8a8 100644 --- a/packages/brightcove-video/ios/RNTBrightcove/RNTBrightcoveView.m +++ b/packages/brightcove-video/ios/RNTBrightcove/RNTBrightcoveView.m @@ -52,11 +52,25 @@ - (void)setup { _progress = 0; _isFinished = NO; + IMASettings *imaSettings = [[IMASettings alloc] init]; + imaSettings.language = @"fr-CA"; + + IMAAdsRenderingSettings *renderSettings = [[IMAAdsRenderingSettings alloc] init]; + renderSettings.webOpenerPresentingController = self.fullscreenViewController; + + BCOVIMAAdsRequestPolicy *adsRequestPolicy = [BCOVIMAAdsRequestPolicy adsRequestPolicyWithVMAPAdTagUrl:_vastTag]; + BCOVPlayerSDKManager *manager = [BCOVPlayerSDKManager sharedManager]; + _playbackController = + [manager createIMAPlaybackControllerWithSettings:imaSettings + adsRenderingSettings:renderSettings + adsRequestPolicy:adsRequestPolicy + adContainer:self + companionSlots:nil + viewStrategy:nil]; - _playbackController = [manager createPlaybackController]; _playbackController.delegate = self; - _playbackController.autoAdvance = YES; + _playbackController.autoAdvance = YES; _playbackController.autoPlay = [_autoplayNumber boolValue]; _playbackService = [[BCOVPlaybackService alloc] initWithAccountId:_accountId @@ -83,11 +97,15 @@ - (void)layoutSubviews { - (void)removeFromSuperview { _eventDispatcher = nil; + for (UIView *subView in self.subviews) + { + [subView removeFromSuperview]; + } [super removeFromSuperview]; } - (void)initPlayerView { - if (_policyKey && _accountId && _videoId && _autoplayNumber && _hideFullScreenButtonNumber) { + if (_policyKey && _accountId && _videoId && _autoplayNumber && _hideFullScreenButtonNumber && _vastTag) { [self setup]; BCOVPUIBasicControlView *controlsView = [BCOVPUIBasicControlView basicControlViewWithVODLayout]; @@ -109,7 +127,6 @@ - (void)initPlayerView { playerView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; _playerView = playerView; - _playerView.playbackController = _playbackController; [self requestContentFromPlaybackService]; } @@ -122,6 +139,13 @@ - (void)setPolicyKey:(NSString *)policyKey { } } +- (void)setVASTTag:(NSString *)vastTag { + if (![vastTag isEqual:_vastTag]) { + _vastTag = vastTag; + [self initPlayerView]; + } +} + - (void)setAccountId:(NSString *)accountId { if (![accountId isEqual:_accountId]) { _accountId = accountId; @@ -228,16 +252,16 @@ - (UIViewController *)rootViewController{ } - (RNTFullscreenPresentingAutoRotatingViewController *)fullscreenViewController { - + if (_fullscreenViewController) { return _fullscreenViewController; } - + RNTFullscreenPresentingAutoRotatingViewController* vc = [RNTFullscreenPresentingAutoRotatingViewController new]; vc.viewControllerToPresentFrom = [self rootViewController]; _fullscreenViewController = vc; - + return _fullscreenViewController; }