I’m working on a project where I need to play two VAST ads in sequence followed by a content video using ExoPlayer in a Flutter app through a method channel. I’ve tried using ConcatenatingMediaSource() but found out that it’s deprecated. Here’s my current implementation:
private fun initializePlayer(id: Int, mainActivity: MainActivity, creationParams: Map<String?, Any?>?, methodChannel: MethodChannel) {
val dataSourceFactory: DataSource.Factory = DefaultDataSourceFactory(playerView.context, Util.getUserAgent(playerView.context, "exo_demo"))
val mediaSourceFactory: MediaSourceFactory = DefaultMediaSourceFactory(dataSourceFactory)
.setAdsLoaderProvider { unusedAdTagUri: AdsConfiguration? -> adsLoader }
.setAdViewProvider(playerView)
trackSelector = DefaultTrackSelector(playerView.context, AdaptiveTrackSelection.Factory())
player = ExoPlayer.Builder(playerView.context)
.setMediaSourceFactory(mediaSourceFactory)
.setTrackSelector(trackSelector!!)
.build()
player!!.preparePlayer(playerView, true, mainActivity, methodChannel)
playerView.player = player
adsLoader!!.setPlayer(player)
playerView.isControllerVisible
playerView.setShowNextButton(false)
playerView.setShowPreviousButton(false)
playerView.showController()
playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT
playerView.controllerHideOnTouch = false
// Parse HLS streaming URL
val url = creationParams as Map<String?, Any?>?
val contentUri = Uri.parse(url?.get("videoURL") as String?)
val contentTitle = url?.get("videoText") as String
// Parse ad tag URI
val adTagUri = Uri.parse("https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_preroll_skippable&sz=640x480&ciu_szs=300x250%2C728x90&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=")
val adTagUri2 = Uri.parse("https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_preroll_skippable&sz=640x480&ciu_szs=300x250%2C728x90&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=")
var adPlaybackState = AdPlaybackState(0, 500 * C.MICROS_PER_SECOND)
adPlaybackState = adPlaybackState.withAdUri(0, 0, adTagUri)
eventListener?.onAdPlaybackState(adPlaybackState);
// Create MediaItem for the ad with ad configuration
val adMediaItem = MediaItem.Builder()
.setUri(contentUri)
.setMimeType(MimeTypes.APPLICATION_M3U8)
.setAdTagUri(adTagUri)
.build()
// Set the media source to the player and prepare it.
player!!.setMediaItem(adMediaItem)
player!!.prepare()
player!!.setPlayWhenReady(true)
}
However, the current implementation only plays the first ad video, and I want to play the second ad video and then the content video. How can I achieve this
Any insights or alternative approaches would be greatly appreciated!