18
ios/Video/DataStructures/AdParams.swift
Normal file
18
ios/Video/DataStructures/AdParams.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
struct AdParams {
|
||||
let adTagUrl: String?
|
||||
let adLanguage: String?
|
||||
|
||||
let json: NSDictionary?
|
||||
|
||||
init(_ json: NSDictionary!) {
|
||||
guard json != nil else {
|
||||
self.json = nil
|
||||
adTagUrl = nil
|
||||
adLanguage = nil
|
||||
return
|
||||
}
|
||||
self.json = json
|
||||
adTagUrl = json["adTagUrl"] as? String
|
||||
adLanguage = json["adLanguage"] as? String
|
||||
}
|
||||
}
|
@@ -12,6 +12,7 @@ struct VideoSource {
|
||||
/* DRM */
|
||||
let drm: DRMParams
|
||||
var textTracks: [TextTrack] = []
|
||||
let adParams: AdParams
|
||||
|
||||
let json: NSDictionary?
|
||||
|
||||
@@ -29,6 +30,7 @@ struct VideoSource {
|
||||
self.cropEnd = nil
|
||||
self.customMetadata = nil
|
||||
self.drm = DRMParams(nil)
|
||||
adParams = AdParams(nil)
|
||||
return
|
||||
}
|
||||
self.json = json
|
||||
@@ -56,5 +58,6 @@ struct VideoSource {
|
||||
self.textTracks = (json["textTracks"] as? NSArray)?.map { trackDict in
|
||||
return TextTrack(trackDict as? NSDictionary)
|
||||
} ?? []
|
||||
adParams = AdParams(json["ad"] as? NSDictionary)
|
||||
}
|
||||
}
|
||||
|
@@ -86,8 +86,6 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
}
|
||||
|
||||
/* IMA Ads */
|
||||
private var _adTagUrl: String?
|
||||
private var _adLanguage: String?
|
||||
#if USE_GOOGLE_IMA
|
||||
private var _imaAdsManager: RCTIMAAdsManager!
|
||||
/* Playhead used by the SDK to track content video progress and insert mid-rolls. */
|
||||
@@ -374,7 +372,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
|
||||
if currentTimeSecs >= 0 {
|
||||
#if USE_GOOGLE_IMA
|
||||
if !_didRequestAds && currentTimeSecs >= 0.0001 && _adTagUrl != nil {
|
||||
if !_didRequestAds && currentTimeSecs >= 0.0001 && _source?.adParams.adTagUrl != nil {
|
||||
_imaAdsManager.requestAds()
|
||||
_didRequestAds = true
|
||||
}
|
||||
@@ -527,7 +525,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
}
|
||||
|
||||
#if USE_GOOGLE_IMA
|
||||
if _adTagUrl != nil {
|
||||
if _source?.adParams.adTagUrl != nil {
|
||||
// Set up your content playhead and contentComplete callback.
|
||||
_contentPlayhead = IMAAVPlayerContentPlayhead(avPlayer: _player!)
|
||||
|
||||
@@ -1216,16 +1214,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
// MARK: - RCTIMAAdsManager
|
||||
|
||||
func getAdLanguage() -> String? {
|
||||
return _adLanguage
|
||||
return _source?.adParams.adLanguage
|
||||
}
|
||||
|
||||
func getAdTagUrl() -> String? {
|
||||
return _adTagUrl
|
||||
}
|
||||
|
||||
@objc
|
||||
func setAdTagUrl(_ adTagUrl: String?) {
|
||||
_adTagUrl = adTagUrl
|
||||
return _source?.adParams.adTagUrl
|
||||
}
|
||||
|
||||
#if USE_GOOGLE_IMA
|
||||
|
@@ -5,8 +5,6 @@
|
||||
|
||||
RCT_EXPORT_VIEW_PROPERTY(src, NSDictionary);
|
||||
RCT_EXPORT_VIEW_PROPERTY(drm, NSDictionary);
|
||||
RCT_EXPORT_VIEW_PROPERTY(adTagUrl, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(adLanguage, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(maxBitRate, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL);
|
||||
|
Reference in New Issue
Block a user