-jio-start-block-type-3
¶ Instream Video Ads-jio-style-title ¶ IntroductionInstream video ads seamlessly integrate within your app's video content, offering various formats like pre-roll, mid-roll, and post-roll. |
![]() |
Complete GETTING STARTED section and INITIALIZE SDK section before starting this section.
-jio-end-block-type-3
-jio-start-block-type-2
-jio-style-title
Cache instream video ads by initializing a JioAdView, setting up an ad delegate, creating an ad container, adding the ad view, and initiating the caching process with a single call to jioAdView?.cacheAd()
jioAdView = JioAdView(adSpotId: ”<ADSPOT_KEY_GOES_HERE>", adType: .instreamVideo,
delegate: self, forPresentionClass: self, publisherContainer: adContainer)
jioAdView?.setCustomView(container: CustomContainer) // For custom layout
jioAdView?.cacheAd()
-jio-style-title
Display the instream video ad when it's in the prepared state, utilizing adView.loadAd()
for rendering
extension InstreamVC : JIOAdViewProtocol {
func onAdPrepared(adView: JioAdView) {
self.showToast(message: "onAdDataPrepared")
adView.loadAd()
}
}
-jio-end-block-type-2
-jio-start-block-type-2
-jio-style-title
Pause and resume video controls using pauseAd()
and resumeAd()
APIs.
jioAdView?.pauseAd()
jioAdView?.resumeAd()
-jio-style-title
Hide/Show Overlay Controls
jioAdView?.hideAdControls()
jioAdView?.showAdControls()
-jio-style-title
jioAdView?.expandAd()
jioAdView?.collapseAd()
-jio-style-title
jioAdView?.setAdPodVariant(podVarient: .defaultAdPod)
jioAdView?.setRequestedAdDuration(adPodDuration: 2)
Ensure proper lifecycle management by calling invalidateAd()
to destroy the Native Ad object
self.adView?.invalidateAd()
self.adView = nil
This API is only available for in-stream video. Any input less than 2 seconds will be ignored.
-jio-end-block-type-2
-jio-start-block-type-2
Customize video ads by defining elements and tags, including controls for Mute/Unmute, Play/Pause, numerical progress, progress bar, Minimize/Maximize, Skip Ad label, CTA button, and ad badge.
jioAdView?.setCustomView(container: customVideoLayout)
-jio-style-title
import UIKit
final public class CustomInstreamLayout: UIView {
@IBOutlet weak var contentView: UIView?
@IBOutlet var btnCTA: UIButton?
@IBOutlet var progressView: UIProgressView?
@IBOutlet var labelTimeIndicator: UILabel?
@IBOutlet var labelAdIndicator: UILabel?
@IBOutlet var btnPlayPause: UIButton?
@IBOutlet var btnExpandCollapse: UIButton?
@IBOutlet var btnMuteUnmute: UIButton?
@IBOutlet weak var skipLabel: UILabel?
@IBOutlet weak var skipAdButton: UIButton?
override init(frame: CGRect) {
super.init(frame: frame)
setUpNib()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setUpNib()
}
func setUpNib() {
let bundle = Bundle(for: type(of: self)).path(forResource: "CustomInstreamLayout", ofType: "nib")
guard bundle != nil else {
SDKLog("Bundle is nil")
return
}
Bundle(for: type(of: self)).loadNibNamed("CustomInstreamLayout", owner: self, options: nil)
guard let contentView = contentView else {
SDKLog("contentView is nil")
return
}
addSubview(contentView)
contentView.frame = self.frame
contentView.tag = VideoAdControlTags.mediaView.rawValue
btnCTA?.tag = VideoAdControlTags.visitAdvertiser.rawValue
progressView?.tag = VideoAdControlTags.progressBar.rawValue
labelTimeIndicator?.tag = VideoAdControlTags.adcounterLbl.rawValue
btnPlayPause?.tag = VideoAdControlTags.playPauseButton.rawValue
skipLabel?.tag = VideoAdControlTags.skipLabel.rawValue
skipAdButton?.tag = VideoAdControlTags.skipButton.rawValue
labelAdIndicator?.tag = VideoAdControlTags.adBadge.rawValue
progressView?.tintColor = .purple
}
}
-jio-end-block-type-2