Skip to content

Commit

Permalink
Release 7.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mobile-ads-github committed Oct 17, 2024
1 parent abd57ef commit 5c9d486
Show file tree
Hide file tree
Showing 32 changed files with 248 additions and 96 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ EULA is available at [EULA website] [LICENSE]
##### Add YandexMobileAds SDK:

```sh
implementation 'com.yandex.android:mobileads:7.5.0'
implementation 'com.yandex.android:mobileads:7.6.0'
```

##### Or you can use our library with all available mediations:
Expand All @@ -31,7 +31,7 @@ implementation 'com.yandex.android:mobileads:7.5.0'

dependencies {
...
implementation 'com.yandex.android:mobileads-mediation:7.5.0.0'
implementation 'com.yandex.android:mobileads-mediation:7.6.0.0'
}
```

Expand Down
2 changes: 1 addition & 1 deletion ThirdPartyMediationAdapterTemplate/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ android {
}

dependencies {
implementation("com.yandex.android:mobileads:7.5.0")
implementation("com.yandex.android:mobileads:7.6.0")
}
4 changes: 3 additions & 1 deletion YandexMobileAdsExample/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ android {

dependencies {
// Yandex Mobile Ads SDK with mediation adapters
implementation("com.yandex.android:mobileads-mediation:7.5.0.0")
implementation("com.yandex.android:mobileads-mediation:7.6.0.0")

implementation("androidx.appcompat:appcompat:1.5.1")
implementation("androidx.activity:activity-ktx:1.6.1")
Expand All @@ -72,6 +72,8 @@ dependencies {
implementation("androidx.coordinatorlayout:coordinatorlayout:1.2.0")
implementation("com.google.android.material:material:1.7.0")
implementation("com.google.android.exoplayer:exoplayer:2.18.1")
implementation("androidx.media3:media3-exoplayer:1.4.1")
implementation("androidx.media3:media3-ui:1.4.1")
implementation("androidx.lifecycle:lifecycle-process:2.4.1")

androidTestImplementation("androidx.test:runner:1.6.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,35 @@

package com.yandex.ads.sample.adunits

import android.net.Uri
import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.commit
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
import com.google.android.exoplayer2.util.Util
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import com.yandex.ads.sample.R
import com.yandex.ads.sample.databinding.ActivitySimpleInstreamAdBinding
import com.yandex.ads.sample.network.Network
import com.yandex.mobile.ads.instream.InstreamAdRequestConfiguration
import com.yandex.mobile.ads.instream.exoplayer.YandexAdsLoader
import com.yandex.mobile.ads.instream.media3.YandexAdsLoader

class SimpleInstreamAdActivity : AppCompatActivity(R.layout.activity_simple_instream_ad) {

private val adInfoFragment get() = requireNotNull(_adInfoFragment)

private var _adInfoFragment: AdInfoFragment? = null
private var player: Player? = null

private var wasPlaying = false
private var rememberedPlayerPosition = 0L
private var rememberedPlayWhenReady = false

private lateinit var binding: ActivitySimpleInstreamAdBinding
private lateinit var yandexAdsLoader: YandexAdsLoader
private lateinit var player: Player


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -47,91 +51,104 @@ class SimpleInstreamAdActivity : AppCompatActivity(R.layout.activity_simple_inst
setReorderingAllowed(true)
replace(R.id.ad_info, adInfoFragment)
}
initPlayer()
initAdsLoader()
}

private fun initPlayer() {
private fun initAdsLoader() {
val configuration = InstreamAdRequestConfiguration
.Builder(networks.first().adUnitId)
.build()
yandexAdsLoader = YandexAdsLoader(this, configuration)
player = createPlayer()
}

private fun initPlayer() {
player = createPlayer().also {
binding.playerView.player = it
yandexAdsLoader.setPlayer(it)

// restore player if was playing before
if (wasPlaying) {
it.setMediaItem(getMediaItem())
it.playWhenReady = rememberedPlayWhenReady
it.seekTo(rememberedPlayerPosition)
it.prepare()
}
}
}

private fun createPlayer(): Player {
val userAgent = Util.getUserAgent(this, getString(R.string.app_name))
val dataSourceFactory = DefaultDataSourceFactory(this, userAgent)
val mediaSourceFactory = DefaultMediaSourceFactory(dataSourceFactory)
.setAdsLoaderProvider { yandexAdsLoader }
.setAdViewProvider(binding.playerView)
val mediaSourceFactory = DefaultMediaSourceFactory(this)
.setLocalAdInsertionComponents({ yandexAdsLoader }, binding.playerView)

val player = SimpleExoPlayer.Builder(this)
val player = ExoPlayer.Builder(this)
.setMediaSourceFactory(mediaSourceFactory)
.build()
binding.playerView.player = player
yandexAdsLoader.setPlayer(player)

return player
}

private fun loadInstream() {
val contentVideoUrl = getString(R.string.instream_content_url)
val mediaItem = MediaItem.Builder()
.setUri(contentVideoUrl)
.setAdTagUri(YandexAdsLoader.AD_TAG_URI).build()

player.apply {
setMediaItem(mediaItem)
prepare()
wasPlaying = true
player?.apply {
setMediaItem(getMediaItem())
playWhenReady = true
prepare()
}
}

private fun restorePlayer() {
yandexAdsLoader.setPlayer(player)
binding.playerView.player = player
if (player.isPlayingAd) {
player.playWhenReady = true
}
private fun getMediaItem(): MediaItem {
val contentVideoUrl = getString(R.string.instream_content_url)
val adTagUri = Uri.parse(YandexAdsLoader.AD_TAG_URI)
val mediaItem = MediaItem.Builder()
.setUri(contentVideoUrl)
.setAdsConfiguration(MediaItem.AdsConfiguration.Builder(adTagUri).build())
.build()
return mediaItem
}


private fun releasePlayer() {
yandexAdsLoader.setPlayer(null)
binding.playerView.player = null
player.playWhenReady = false
player?.also {
rememberedPlayerPosition = it.contentPosition
rememberedPlayWhenReady = it.playWhenReady
it.release()
}
player = null
}

override fun onStart() {
super.onStart()
if (Util.SDK_INT <= Build.VERSION_CODES.M) return
restorePlayer()
if (Build.VERSION.SDK_INT <= 23) return
initPlayer()
binding.playerView.onResume()
}

override fun onStop() {
super.onStop()
if (Util.SDK_INT <= Build.VERSION_CODES.M) return
if (Build.VERSION.SDK_INT <= 23) return
binding.playerView.onPause()
releasePlayer()
}

override fun onResume() {
super.onResume()
if (Util.SDK_INT > Build.VERSION_CODES.M) return
restorePlayer()
if (Build.VERSION.SDK_INT > 23) return
initPlayer()
binding.playerView.onResume()
}

override fun onPause() {
super.onPause()
if (Util.SDK_INT > Build.VERSION_CODES.M) return
if (Build.VERSION.SDK_INT > 23) return
binding.playerView.onPause()
releasePlayer()
}

override fun onDestroy() {
releasePlayer()
yandexAdsLoader.release()
player.release()
_adInfoFragment = null
super.onDestroy()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,29 @@ import android.media.MediaCodec
import android.media.MediaDrmResetException
import android.media.ResourceBusyException
import android.os.Build
import com.google.android.exoplayer2.ExoPlaybackException
import com.google.android.exoplayer2.ExoTimeoutException
import com.google.android.exoplayer2.IllegalSeekPositionException
import com.google.android.exoplayer2.ParserException
import com.google.android.exoplayer2.audio.AudioSink
import com.google.android.exoplayer2.audio.DefaultAudioSink
import com.google.android.exoplayer2.drm.DrmSession
import com.google.android.exoplayer2.drm.KeysExpiredException
import com.google.android.exoplayer2.mediacodec.MediaCodecRenderer
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil
import com.google.android.exoplayer2.source.BehindLiveWindowException
import com.google.android.exoplayer2.text.SubtitleDecoderException
import com.google.android.exoplayer2.upstream.HttpDataSource
import com.google.android.exoplayer2.upstream.Loader
import com.google.android.exoplayer2.upstream.cache.Cache
import com.google.android.exoplayer2.video.MediaCodecVideoDecoderException
import androidx.annotation.OptIn
import androidx.media3.common.IllegalSeekPositionException
import androidx.media3.common.ParserException
import androidx.media3.common.util.UnstableApi
import androidx.media3.datasource.HttpDataSource
import androidx.media3.datasource.cache.Cache
import androidx.media3.exoplayer.ExoPlaybackException
import androidx.media3.exoplayer.ExoTimeoutException
import androidx.media3.exoplayer.audio.AudioSink
import androidx.media3.exoplayer.audio.DefaultAudioSink
import androidx.media3.exoplayer.drm.DrmSession
import androidx.media3.exoplayer.drm.KeysExpiredException
import androidx.media3.exoplayer.mediacodec.MediaCodecRenderer
import androidx.media3.exoplayer.mediacodec.MediaCodecUtil
import androidx.media3.exoplayer.source.BehindLiveWindowException
import androidx.media3.exoplayer.upstream.Loader
import androidx.media3.exoplayer.video.MediaCodecVideoDecoderException
import androidx.media3.extractor.text.SubtitleDecoderException
import com.yandex.mobile.ads.instream.player.ad.error.InstreamAdPlayerError
import java.net.HttpURLConnection
import javax.net.ssl.SSLHandshakeException

@OptIn(UnstableApi::class)
class ExoPlayerErrorConverter {

fun convertExoPlayerError(throwable: Throwable): InstreamAdPlayerError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

package com.yandex.ads.sample.player.ad

import com.google.android.exoplayer2.ui.PlayerView
import androidx.media3.ui.PlayerView
import com.yandex.ads.sample.player.SamplePlayer
import com.yandex.mobile.ads.instream.player.ad.InstreamAdPlayer
import com.yandex.mobile.ads.instream.player.ad.InstreamAdPlayerListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@

package com.yandex.ads.sample.player.ad

import com.google.android.exoplayer2.PlaybackException
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.ui.PlayerView
import androidx.annotation.OptIn
import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.PlayerView
import com.yandex.ads.sample.player.creator.MediaSourceCreator
import com.yandex.mobile.ads.instream.player.ad.InstreamAdPlayerListener
import com.yandex.mobile.ads.video.playback.model.VideoAd

@OptIn(UnstableApi::class)
class SampleVideoAdPlayer(
private val videoAd: VideoAd,
private val exoPlayerView: PlayerView,
Expand All @@ -26,7 +29,7 @@ class SampleVideoAdPlayer(
private val exoPlayerErrorConverter = ExoPlayerErrorConverter()
private val mediaSourceCreator = MediaSourceCreator(context)

private val adPlayer = SimpleExoPlayer.Builder(context).build().apply {
private val adPlayer = ExoPlayer.Builder(context).build().apply {
addListener(ExoPlayerEventsListener())
}

Expand Down Expand Up @@ -132,6 +135,7 @@ class SampleVideoAdPlayer(
}
Player.STATE_BUFFERING -> onAdBufferingStarted()
Player.STATE_ENDED -> onEndedState()
else -> { }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
package com.yandex.ads.sample.player.cache

import android.content.Context
import com.google.android.exoplayer2.database.ExoDatabaseProvider
import com.google.android.exoplayer2.upstream.cache.Cache
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor
import com.google.android.exoplayer2.upstream.cache.SimpleCache

import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi
import androidx.media3.database.StandaloneDatabaseProvider
import androidx.media3.datasource.cache.Cache
import androidx.media3.datasource.cache.LeastRecentlyUsedCacheEvictor
import androidx.media3.datasource.cache.SimpleCache

@OptIn(UnstableApi::class)
object DiskCacheProvider {

private const val CACHE_DIRECTORY_NAME = "video-cache"
Expand All @@ -34,7 +37,7 @@ object DiskCacheProvider {
private fun createCache(context: Context): Cache {
val cacheDir = diskCachePathProvider.getDiskCacheDirectory(context, CACHE_DIRECTORY_NAME)
val cacheEvictor = LeastRecentlyUsedCacheEvictor(MIN_DISK_CACHE_SIZE_BYTES)
val databaseProvider = ExoDatabaseProvider(context)
val databaseProvider = StandaloneDatabaseProvider(context)

return SimpleCache(cacheDir, cacheEvictor, databaseProvider)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@

package com.yandex.ads.sample.player.content

import com.google.android.exoplayer2.PlaybackException
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.ui.PlayerView

import androidx.annotation.OptIn
import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.PlayerView
import com.yandex.ads.sample.player.SamplePlayer
import com.yandex.ads.sample.player.creator.MediaSourceCreator
import com.yandex.mobile.ads.instream.player.content.VideoPlayer
import com.yandex.mobile.ads.instream.player.content.VideoPlayerListener

@OptIn(UnstableApi::class)
class ContentVideoPlayer(
private val videoUrl: String,
private val exoPlayerView: PlayerView
) : VideoPlayer, SamplePlayer {

private val context = exoPlayerView.context
private val exoPlayer = SimpleExoPlayer.Builder(context).build()
private val exoPlayer = ExoPlayer.Builder(context).build()
private val mediaSourceCreator = MediaSourceCreator(context)

private var videoPlayerListener: VideoPlayerListener? = null
Expand Down Expand Up @@ -71,8 +75,8 @@ class ContentVideoPlayer(
resume()
}

override fun setVideoPlayerListener(playerListener: VideoPlayerListener?) {
videoPlayerListener = playerListener
override fun setVideoPlayerListener(listener: VideoPlayerListener?) {
videoPlayerListener = listener
}

fun release() {
Expand Down
Loading

0 comments on commit 5c9d486

Please sign in to comment.