Skip to content

Commit

Permalink
Fix various issues with ads (#33)
Browse files Browse the repository at this point in the history
* video controller visibility

change the visibility of video controller when Ads are playing.

* Simplify

* Use adbreakbegin/end to update isPlayingAd

* Update changelog

---------

Co-authored-by: m-derakhshan <[email protected]>
  • Loading branch information
MattiasBuelens and m-derakhshan authored Aug 28, 2024
1 parent 80f608f commit 8759705
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
## v1.7.1 (2024-08-20)

* 🐛 Disable system gestures on the `SeekBar` component. ([#30](https://github.com/THEOplayer/android-ui/pull/30))
* 🐛 Fixed ad clickthrough not working. ([#33](https://github.com/THEOplayer/android-ui/pull/33))
* 🐛 Fixed UI not re-appearing after playing an ad. ([#33](https://github.com/THEOplayer/android-ui/pull/33))

## v1.7.0 (2024-08-12)

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ui-test-junit4 = "1.6.8" # ...not in BOM for some reason?
androidx-junit = "1.2.1"
androidx-espresso = "3.6.1"
dokka = "1.9.20"
theoplayer = "7.8.0"
theoplayer = "7.10.0"

[libraries]
androidx-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "ktx" }
Expand Down
12 changes: 7 additions & 5 deletions ui/src/main/java/com/theoplayer/android/ui/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player
}

private fun updatePlayingAd() {
playingAd = player?.ads?.isPlaying ?: false
playingAd = ads?.isPlaying ?: false
}

private val playListener = EventListener<PlayEvent> { updateCurrentTimeAndPlaybackState() }
Expand Down Expand Up @@ -680,8 +680,9 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player
TextTrackListEventTypes.TRACKLISTCHANGE,
textTrackListChangeListener
)
ads?.addEventListener(AdsEventTypes.AD_BEGIN, adListener)
ads?.addEventListener(AdsEventTypes.AD_END, adListener)
ads?.addEventListener(AdsEventTypes.AD_BREAK_BEGIN, adListener)
ads?.addEventListener(AdsEventTypes.AD_SKIP, adListener)
ads?.addEventListener(AdsEventTypes.AD_BREAK_END, adListener)
cast?.chromecast?.addEventListener(
ChromecastEventTypes.STATECHANGE,
chromecastStateChangeListener
Expand Down Expand Up @@ -745,8 +746,9 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player
TextTrackListEventTypes.TRACKLISTCHANGE,
textTrackListChangeListener
)
ads?.removeEventListener(AdsEventTypes.AD_BEGIN, adListener)
ads?.removeEventListener(AdsEventTypes.AD_END, adListener)
ads?.removeEventListener(AdsEventTypes.AD_BREAK_BEGIN, adListener)
ads?.removeEventListener(AdsEventTypes.AD_SKIP, adListener)
ads?.removeEventListener(AdsEventTypes.AD_BREAK_END, adListener)
cast?.chromecast?.removeEventListener(
ChromecastEventTypes.STATECHANGE,
chromecastStateChangeListener
Expand Down
43 changes: 38 additions & 5 deletions ui/src/main/java/com/theoplayer/android/ui/UIController.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
package com.theoplayer.android.ui

import android.view.ViewGroup
import androidx.compose.animation.*
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.slideOutVertically
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background
import androidx.compose.foundation.interaction.Interaction
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.*
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.viewinterop.AndroidView
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
Expand All @@ -22,7 +51,7 @@ import com.theoplayer.android.api.THEOplayerView
import com.theoplayer.android.api.cast.chromecast.PlayerCastState
import com.theoplayer.android.api.source.SourceDescription
import com.theoplayer.android.ui.theme.THEOplayerTheme
import kotlinx.coroutines.*
import kotlinx.coroutines.delay
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
import kotlin.time.DurationUnit
Expand Down Expand Up @@ -188,6 +217,10 @@ fun UIController(

PlayerContainer(modifier = modifier, player = player) {
CompositionLocalProvider(LocalPlayer provides player) {
if (player.playingAd) {
// Remove player UI entirely while playing an ad, to make clickthrough work
return@CompositionLocalProvider
}
AnimatedContent(
label = "ContentAnimation",
modifier = Modifier
Expand Down

0 comments on commit 8759705

Please sign in to comment.