Skip to content

Commit

Permalink
video controller visibility
Browse files Browse the repository at this point in the history
change the visibility of video controller when Ads are playing.
  • Loading branch information
m-derakhshan committed Aug 22, 2024
1 parent 9afb16f commit 741ffe7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
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
13 changes: 10 additions & 3 deletions ui/src/main/java/com/theoplayer/android/ui/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.theoplayer.android.api.cast.Cast
import com.theoplayer.android.api.cast.chromecast.PlayerCastState
import com.theoplayer.android.api.error.THEOplayerException
import com.theoplayer.android.api.event.EventListener
import com.theoplayer.android.api.event.ads.AdBeginEvent
import com.theoplayer.android.api.event.ads.AdEvent
import com.theoplayer.android.api.event.ads.AdsEventTypes
import com.theoplayer.android.api.event.chromecast.CastErrorEvent
Expand Down Expand Up @@ -347,8 +348,11 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player
videoHeight = player?.videoHeight ?: 0
}

private fun updatePlayingAd() {
playingAd = player?.ads?.isPlaying ?: false
private fun updatePlayingAd(event: AdEvent<*>? = null) {
playingAd = when (event) {
is AdBeginEvent -> true
else -> false
}
}

private val playListener = EventListener<PlayEvent> { updateCurrentTimeAndPlaybackState() }
Expand All @@ -362,7 +366,9 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player
private val readyStateChangeListener =
EventListener<ReadyStateChangeEvent> { updateCurrentTimeAndPlaybackState() }
private val resizeListener = EventListener<ResizeEvent> { updateVideoWidthAndHeight() }
private val adListener = EventListener<AdEvent<*>> { updatePlayingAd() }
private val adListener = EventListener<AdEvent<*>> {
updatePlayingAd(it)
}
private val sourceChangeListener = EventListener<SourceChangeEvent> {
_source = player?.source
error = null
Expand Down Expand Up @@ -681,6 +687,7 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player
textTrackListChangeListener
)
ads?.addEventListener(AdsEventTypes.AD_BEGIN, adListener)
ads?.addEventListener(AdsEventTypes.AD_SKIP, adListener)
ads?.addEventListener(AdsEventTypes.AD_END, adListener)
cast?.chromecast?.addEventListener(
ChromecastEventTypes.STATECHANGE,
Expand Down
42 changes: 36 additions & 6 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 @@ -330,7 +359,8 @@ private fun PlayerContainer(
ViewCompositionStrategy.DisposeOnLifecycleDestroyed(lifecycle)
)
setContent {
ui()
if (player.playingAd.not())
ui()
}
}
// Host the THEOplayer view inside our AndroidView
Expand Down

0 comments on commit 741ffe7

Please sign in to comment.