Merge pull request #3062 from iFeelSmart/chore/disableImaByDefault
fix: disable Google IMA by default on ios.
This commit is contained in:
commit
05864dc64a
11
API.md
11
API.md
@ -74,6 +74,17 @@ Video with caching ([more info](docs/caching.md)):
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Enable custom feature in podfile file
|
||||||
|
|
||||||
|
##### Google IMA
|
||||||
|
|
||||||
|
Google IMA is the google SDK to support Client Side Ads Integration (CSAI), see [google documentation](https://developers.google.com/interactive-media-ads/docs/sdks/ios/client-side) for more informations.
|
||||||
|
|
||||||
|
To enable google IMA usage define add following line in your podfile:
|
||||||
|
```podfile
|
||||||
|
$RNVideoUseGoogleIMA=true
|
||||||
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### tvOS installation
|
### tvOS installation
|
||||||
|
@ -7,6 +7,8 @@ install! 'cocoapods', :deterministic_uuids => false
|
|||||||
target 'videoplayer' do
|
target 'videoplayer' do
|
||||||
config = use_native_modules!
|
config = use_native_modules!
|
||||||
|
|
||||||
|
# $RNVideoUseGoogleIMA = true
|
||||||
|
|
||||||
# Flags change depending on the env values.
|
# Flags change depending on the env values.
|
||||||
flags = get_default_flags()
|
flags = get_default_flags()
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#if USE_GOOGLE_IMA
|
||||||
import Foundation
|
import Foundation
|
||||||
import GoogleInteractiveMediaAds
|
import GoogleInteractiveMediaAds
|
||||||
|
|
||||||
@ -185,3 +186,4 @@ class RCTIMAAdsManager: NSObject, IMAAdsLoaderDelegate, IMAAdsManagerDelegate {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import AVFoundation
|
import AVFoundation
|
||||||
import AVKit
|
import AVKit
|
||||||
import Foundation
|
import Foundation
|
||||||
|
#if USE_GOOGLE_IMA
|
||||||
import GoogleInteractiveMediaAds
|
import GoogleInteractiveMediaAds
|
||||||
|
#endif
|
||||||
import React
|
import React
|
||||||
import Promises
|
import Promises
|
||||||
|
|
||||||
@ -63,11 +65,13 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
|
|
||||||
/* IMA Ads */
|
/* IMA Ads */
|
||||||
private var _adTagUrl:String?
|
private var _adTagUrl:String?
|
||||||
|
#if USE_GOOGLE_IMA
|
||||||
private var _imaAdsManager: RCTIMAAdsManager!
|
private var _imaAdsManager: RCTIMAAdsManager!
|
||||||
private var _didRequestAds:Bool = false
|
|
||||||
private var _adPlaying:Bool = false
|
|
||||||
/* Playhead used by the SDK to track content video progress and insert mid-rolls. */
|
/* Playhead used by the SDK to track content video progress and insert mid-rolls. */
|
||||||
private var _contentPlayhead: IMAAVPlayerContentPlayhead?
|
private var _contentPlayhead: IMAAVPlayerContentPlayhead?
|
||||||
|
#endif
|
||||||
|
private var _didRequestAds:Bool = false
|
||||||
|
private var _adPlaying:Bool = false
|
||||||
|
|
||||||
private var _resouceLoaderDelegate: RCTResourceLoaderDelegate?
|
private var _resouceLoaderDelegate: RCTResourceLoaderDelegate?
|
||||||
private var _playerObserver: RCTPlayerObserver = RCTPlayerObserver()
|
private var _playerObserver: RCTPlayerObserver = RCTPlayerObserver()
|
||||||
@ -107,8 +111,9 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
|
|
||||||
init(eventDispatcher:RCTEventDispatcher!) {
|
init(eventDispatcher:RCTEventDispatcher!) {
|
||||||
super.init(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
|
super.init(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
|
||||||
|
#if USE_GOOGLE_IMA
|
||||||
_imaAdsManager = RCTIMAAdsManager(video: self)
|
_imaAdsManager = RCTIMAAdsManager(video: self)
|
||||||
|
#endif
|
||||||
|
|
||||||
_eventDispatcher = eventDispatcher
|
_eventDispatcher = eventDispatcher
|
||||||
|
|
||||||
@ -147,8 +152,9 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
required init?(coder aDecoder: NSCoder) {
|
||||||
super.init(coder: aDecoder)
|
super.init(coder: aDecoder)
|
||||||
|
#if USE_GOOGLE_IMA
|
||||||
_imaAdsManager = RCTIMAAdsManager(video: self)
|
_imaAdsManager = RCTIMAAdsManager(video: self)
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
@ -217,10 +223,12 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
])
|
])
|
||||||
|
|
||||||
if currentTimeSecs >= 0 {
|
if currentTimeSecs >= 0 {
|
||||||
|
#if USE_GOOGLE_IMA
|
||||||
if !_didRequestAds && currentTimeSecs >= 0.0001 && _adTagUrl != nil {
|
if !_didRequestAds && currentTimeSecs >= 0.0001 && _adTagUrl != nil {
|
||||||
_imaAdsManager.requestAds()
|
_imaAdsManager.requestAds()
|
||||||
_didRequestAds = true
|
_didRequestAds = true
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
onVideoProgress?([
|
onVideoProgress?([
|
||||||
"currentTime": NSNumber(value: Float(currentTimeSecs)),
|
"currentTime": NSNumber(value: Float(currentTimeSecs)),
|
||||||
"playableDuration": RCTVideoUtils.calculatePlayableDuration(_player),
|
"playableDuration": RCTVideoUtils.calculatePlayableDuration(_player),
|
||||||
@ -307,13 +315,14 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
self.setAutomaticallyWaitsToMinimizeStalling(self._automaticallyWaitsToMinimizeStalling)
|
self.setAutomaticallyWaitsToMinimizeStalling(self._automaticallyWaitsToMinimizeStalling)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_GOOGLE_IMA
|
||||||
if self._adTagUrl != nil {
|
if self._adTagUrl != nil {
|
||||||
// Set up your content playhead and contentComplete callback.
|
// Set up your content playhead and contentComplete callback.
|
||||||
self._contentPlayhead = IMAAVPlayerContentPlayhead(avPlayer: self._player!)
|
self._contentPlayhead = IMAAVPlayerContentPlayhead(avPlayer: self._player!)
|
||||||
|
|
||||||
self._imaAdsManager.setUpAdsLoader()
|
self._imaAdsManager.setUpAdsLoader()
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
//Perform on next run loop, otherwise onVideoLoadStart is nil
|
//Perform on next run loop, otherwise onVideoLoadStart is nil
|
||||||
self.onVideoLoadStart?([
|
self.onVideoLoadStart?([
|
||||||
"src": [
|
"src": [
|
||||||
@ -424,7 +433,9 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
func setPaused(_ paused:Bool) {
|
func setPaused(_ paused:Bool) {
|
||||||
if paused {
|
if paused {
|
||||||
if _adPlaying {
|
if _adPlaying {
|
||||||
|
#if USE_GOOGLE_IMA
|
||||||
_imaAdsManager.getAdsManager()?.pause()
|
_imaAdsManager.getAdsManager()?.pause()
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
_player?.pause()
|
_player?.pause()
|
||||||
_player?.rate = 0.0
|
_player?.rate = 0.0
|
||||||
@ -433,7 +444,9 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
RCTPlayerOperations.configureAudio(ignoreSilentSwitch:_ignoreSilentSwitch, mixWithOthers:_mixWithOthers)
|
RCTPlayerOperations.configureAudio(ignoreSilentSwitch:_ignoreSilentSwitch, mixWithOthers:_mixWithOthers)
|
||||||
|
|
||||||
if _adPlaying {
|
if _adPlaying {
|
||||||
|
#if USE_GOOGLE_IMA
|
||||||
_imaAdsManager.getAdsManager()?.resume()
|
_imaAdsManager.getAdsManager()?.resume()
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
if #available(iOS 10.0, *), !_automaticallyWaitsToMinimizeStalling {
|
if #available(iOS 10.0, *), !_automaticallyWaitsToMinimizeStalling {
|
||||||
_player?.playImmediately(atRate: _rate)
|
_player?.playImmediately(atRate: _rate)
|
||||||
@ -824,11 +837,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
func setAdTagUrl(_ adTagUrl:String!) {
|
func setAdTagUrl(_ adTagUrl:String!) {
|
||||||
_adTagUrl = adTagUrl
|
_adTagUrl = adTagUrl
|
||||||
}
|
}
|
||||||
|
#if USE_GOOGLE_IMA
|
||||||
func getContentPlayhead() -> IMAAVPlayerContentPlayhead? {
|
func getContentPlayhead() -> IMAAVPlayerContentPlayhead? {
|
||||||
return _contentPlayhead
|
return _contentPlayhead
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
func setAdPlaying(_ adPlaying:Bool) {
|
func setAdPlaying(_ adPlaying:Bool) {
|
||||||
_adPlaying = adPlaying
|
_adPlaying = adPlaying
|
||||||
}
|
}
|
||||||
@ -1106,11 +1119,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
|
|
||||||
@objc func handlePlayerItemDidReachEnd(notification:NSNotification!) {
|
@objc func handlePlayerItemDidReachEnd(notification:NSNotification!) {
|
||||||
onVideoEnd?(["target": reactTag as Any])
|
onVideoEnd?(["target": reactTag as Any])
|
||||||
|
#if USE_GOOGLE_IMA
|
||||||
if notification.object as? AVPlayerItem == _player?.currentItem {
|
if notification.object as? AVPlayerItem == _player?.currentItem {
|
||||||
_imaAdsManager.getAdsLoader()?.contentComplete()
|
_imaAdsManager.getAdsLoader()?.contentComplete()
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if _repeat {
|
if _repeat {
|
||||||
let item:AVPlayerItem! = notification.object as? AVPlayerItem
|
let item:AVPlayerItem! = notification.object as? AVPlayerItem
|
||||||
item.seek(to: CMTime.zero, completionHandler: nil)
|
item.seek(to: CMTime.zero, completionHandler: nil)
|
||||||
|
@ -19,8 +19,15 @@ Pod::Spec.new do |s|
|
|||||||
ss.source_files = "ios/Video/**/*.{h,m,swift}"
|
ss.source_files = "ios/Video/**/*.{h,m,swift}"
|
||||||
ss.dependency "PromisesSwift"
|
ss.dependency "PromisesSwift"
|
||||||
|
|
||||||
|
if defined?($RNVideoUseGoogleIMA)
|
||||||
|
Pod::UI.puts "RNVideo: enable IMA SDK"
|
||||||
|
|
||||||
ss.ios.dependency 'GoogleAds-IMA-iOS-SDK', '~> 3.18.1'
|
ss.ios.dependency 'GoogleAds-IMA-iOS-SDK', '~> 3.18.1'
|
||||||
ss.tvos.dependency 'GoogleAds-IMA-tvOS-SDK', '~> 4.2'
|
ss.tvos.dependency 'GoogleAds-IMA-tvOS-SDK', '~> 4.2'
|
||||||
|
ss.pod_target_xcconfig = {
|
||||||
|
'OTHER_SWIFT_FLAGS' => '$(inherited) -D USE_GOOGLE_IMA'
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
s.subspec "VideoCaching" do |ss|
|
s.subspec "VideoCaching" do |ss|
|
||||||
|
Loading…
Reference in New Issue
Block a user