[ADS] Add play/pause capability while ad is playing
This commit is contained in:
parent
f54288c54d
commit
f521f8f0dc
@ -61,7 +61,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
private var _filterEnabled:Bool = false
|
private var _filterEnabled:Bool = false
|
||||||
private var _adTagUrl:String?
|
private var _adTagUrl:String?
|
||||||
private var _presentingViewController:UIViewController?
|
private var _presentingViewController:UIViewController?
|
||||||
private var _didRequestedAds:Bool = false
|
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()
|
||||||
@ -214,9 +215,9 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
])
|
])
|
||||||
|
|
||||||
if currentTimeSecs >= 0 {
|
if currentTimeSecs >= 0 {
|
||||||
if !_didRequestedAds && currentTimeSecs >= 0.0001 {
|
if !_didRequestAds && currentTimeSecs >= 0.0001 {
|
||||||
requestAds()
|
requestAds()
|
||||||
_didRequestedAds = true
|
_didRequestAds = true
|
||||||
}
|
}
|
||||||
onVideoProgress?([
|
onVideoProgress?([
|
||||||
"currentTime": NSNumber(value: Float(currentTimeSecs)),
|
"currentTime": NSNumber(value: Float(currentTimeSecs)),
|
||||||
@ -420,18 +421,26 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
@objc
|
@objc
|
||||||
func setPaused(_ paused:Bool) {
|
func setPaused(_ paused:Bool) {
|
||||||
if paused {
|
if paused {
|
||||||
_player?.pause()
|
if _adPlaying {
|
||||||
_player?.rate = 0.0
|
adsManager?.pause()
|
||||||
|
} else {
|
||||||
|
_player?.pause()
|
||||||
|
_player?.rate = 0.0
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
RCTPlayerOperations.configureAudio(ignoreSilentSwitch:_ignoreSilentSwitch, mixWithOthers:_mixWithOthers)
|
RCTPlayerOperations.configureAudio(ignoreSilentSwitch:_ignoreSilentSwitch, mixWithOthers:_mixWithOthers)
|
||||||
|
|
||||||
if #available(iOS 10.0, *), !_automaticallyWaitsToMinimizeStalling {
|
if _adPlaying {
|
||||||
_player?.playImmediately(atRate: _rate)
|
adsManager?.resume()
|
||||||
} else {
|
} else {
|
||||||
_player?.play()
|
if #available(iOS 10.0, *), !_automaticallyWaitsToMinimizeStalling {
|
||||||
|
_player?.playImmediately(atRate: _rate)
|
||||||
|
} else {
|
||||||
|
_player?.play()
|
||||||
|
_player?.rate = _rate
|
||||||
|
}
|
||||||
_player?.rate = _rate
|
_player?.rate = _rate
|
||||||
}
|
}
|
||||||
_player?.rate = _rate
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_paused = paused
|
_paused = paused
|
||||||
@ -1150,7 +1159,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
print("Error loading ads: " + adErrorData.adError.message!)
|
print("Error loading ads: " + adErrorData.adError.message!)
|
||||||
}
|
}
|
||||||
|
|
||||||
_player?.play()
|
setPaused(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - IMAAdsManagerDelegate
|
// MARK: - IMAAdsManagerDelegate
|
||||||
@ -1177,16 +1186,18 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to playing content
|
// Fall back to playing content
|
||||||
_player?.play()
|
setPaused(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func adsManagerDidRequestContentPause(_ adsManager: IMAAdsManager) {
|
func adsManagerDidRequestContentPause(_ adsManager: IMAAdsManager) {
|
||||||
// Pause the content for the SDK to play ads.
|
// Pause the content for the SDK to play ads.
|
||||||
setPaused(true)
|
setPaused(true)
|
||||||
|
_adPlaying = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func adsManagerDidRequestContentResume(_ adsManager: IMAAdsManager) {
|
func adsManagerDidRequestContentResume(_ adsManager: IMAAdsManager) {
|
||||||
// Resume the content since the SDK is done playing ads (at least for now).
|
// Resume the content since the SDK is done playing ads (at least for now).
|
||||||
|
_adPlaying = false
|
||||||
setPaused(false)
|
setPaused(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user