Hello team,
I want to fetch and play a video ad using exoplayer ima(androidx.media3:media3-exoplayer-ima). My problem is that I don't have the content's uri to set in the
ImaAdsLoader object. if I am not setting the content uri using the setUri() method of the ImaAdsLoader object, it plays the ad but it is not giving the "ALL_ADS_COMPLETED" or "COMPLETE" event. Is there an alternative to this where there is no need to set the content uri and get the "
ALL_ADS_COMPLETED" or "COMPLETE" event.
i am using the below dependencies
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.29.0'
//media3 exoplayer
implementation "androidx.media3:media3-exoplayer:1.2.0"
implementation "androidx.media3:media3-ui:1.2.0"
implementation "androidx.media3:media3-exoplayer-ima:1.2.0"
implementation "androidx.media3:media3-datasource-okhttp:1.2.0"
Related Code snippet:
playerView = PlayerView(context!!)
// Create an AdsLoader.
adsLoader = ImaAdsLoader.Builder(context!!)
.setAdEventListener(this) // here i am not using setUri() method because i don't have the content's uri
.build()
// Set up the factory for media sources, passing the ads loader and ad view providers.
val dataSourceFactory: DataSource.Factory = DefaultDataSource.Factory(context!!)
val mediaSourceFactory: MediaSource.Factory =
DefaultMediaSourceFactory(dataSourceFactory)
.setLocalAdInsertionComponents(
{ adsLoader },
playerView!!
)
// Create an ExoPlayer and set it as the player for content and ads.
player = ExoPlayer.Builder(context!!).setMediaSourceFactory(mediaSourceFactory).build()
playerView!!.player = player
playerView!!.useController = false
adsLoader!!.setPlayer(player)
val mediaItem = MediaItem.Builder()
.setUri(Uri.parse(""))
.setAdsConfiguration(
MediaItem.AdsConfiguration.Builder(Uri.parse(vastAdTagUri!!)).build()
)
.build()
// Prepare the content and ad to be played with the SimpleExoPlayer.
player!!.setMediaItem(mediaItem)
player!!.prepare()
// Set PlayWhenReady. If true, content and ads will autoplay.
player!!.playWhenReady = false
*************************CONFIDENTIALITY CAUTION
This communication (including any accompanying
documents) is intended only for the use of the addressee(s) and contains
PRIVATE AND CONFIDENTIAL information. Unauthorized reading,
dissemination, distribution or copying of this communication is
prohibited. If you have received this communication in error, please
notify us immediately by e-mail and promptly destroy the original
communication. Please do not copy it or use it for any other purposes,
or disclose its contents to any other person. Unless stated to the
contrary, any opinions or comments are personal to the writer and do not
represent the official view of the Company. In case where it represents
our official view, it needs to be revalidated and is subject to the
terms of our engagement.
Thank you for your co-operation.
*************************