I am using the below code in fragement which extend VideoSupportFragment
adsLoader = ImaAdsLoader.Builder(requireContext())
.setAdEventListener(AdsEventListener())
.build()
val dataSourceFactory: DataSource.Factory = DefaultDataSource.Factory(requireContext())
val mediaSourceFactory: MediaSource.Factory = DefaultMediaSourceFactory(dataSourceFactory)
.setLocalAdInsertionComponents({ adsLoader }, { mPlayerView })
// Create an ExoPlayer and set it as the player for content and ads.
mPlayer =
ExoPlayer.Builder(requireContext())
.setMediaSourceFactory(mediaSourceFactory)
.build()
and player code
adsLoader?.setPlayer(mPlayer)
val tagUrl = "https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dskippablelinear&correlator=4353245"
// Create the MediaItem to play, specifying the content URI and ad tag URI.
val contentUri = Uri.parse(video.videoUrl)
val adTagUri = Uri.parse(tagUrl)
val mediaItem = MediaItem.Builder()
.setUri(contentUri)
.setAdsConfiguration(MediaItem.AdsConfiguration.Builder(adTagUri).build())
.build()
// Prepare the content and ad to be played with the SimpleExoPlayer.
mPlayer?.addListener(mEventListener)
mPlayer?.setMediaItem(mediaItem)
mPlayer?.prepare()
It's working fine, but not showing the skip countdown as well as the skip button. I have tried and tested 4-5 skippable ads, but no one is displaying the skip button Working on Android TV using Leanback Lib.