Skip to content

Commit

Permalink
added loading info on android
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Dec 3, 2023
1 parent 94dfafa commit 2e59e76
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import androidx.media3.ui.PlayerView
import com.arkivanov.decompose.extensions.compose.jetbrains.subscribeAsState
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.google.android.gms.cast.framework.CastState
import com.google.android.material.progressindicator.CircularProgressIndicator
import dev.datlag.burningseries.model.common.scopeCatching
import dev.datlag.burningseries.shared.R
import dev.datlag.burningseries.shared.SharedRes
Expand Down Expand Up @@ -139,6 +140,8 @@ actual fun VideoScreen(component: VideoComponent) {
subtitles = languages
}

var displayLoading by remember { mutableStateOf(true) }

val playListener = remember { object : Player.Listener {
override fun onPlayerError(error: PlaybackException) {
super.onPlayerError(error)
Expand All @@ -159,8 +162,17 @@ actual fun VideoScreen(component: VideoComponent) {
override fun onPlaybackStateChanged(playbackState: Int) {
super.onPlaybackStateChanged(playbackState)

if (playbackState == Player.STATE_ENDED) {
component.ended()
when (playbackState) {
Player.STATE_ENDED -> {
displayLoading = false
component.ended()
}
Player.STATE_IDLE, Player.STATE_BUFFERING -> {
displayLoading = true
}
else -> {
displayLoading = false
}
}
}
} }
Expand Down Expand Up @@ -369,6 +381,7 @@ actual fun VideoScreen(component: VideoComponent) {
val subtitleButton = controls.findViewById<ImageButton>(R.id.subtitle)
val progress = controls.findViewById<DefaultTimeBar>(R.id.exo_progress)
val mediaRouteButton = controls.findViewById<ImageButton>(R.id.cast_button)
val loadingIndicator = controls.findViewById<CircularProgressIndicator>(R.id.loading_indicator)

playerView.player = usingPlayer

Expand All @@ -381,6 +394,13 @@ actual fun VideoScreen(component: VideoComponent) {
}
mediaRouteButton.setImageResource(castIcon)

loadingIndicator.setIndicatorColor(progressColor)
loadingIndicator.visibility = if (displayLoading) {
View.VISIBLE
} else {
View.GONE
}

if (subtitles.isNotEmpty()) {
subtitleButton.visibility = View.VISIBLE
subtitleButton.isEnabled = true
Expand Down
23 changes: 18 additions & 5 deletions app/shared/src/androidMain/res/layout/exoplayer_controls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,24 @@
android:src="@drawable/baseline_replay_10_24"
style="@style/ExoMediaButton.Rewind"/>

<androidx.appcompat.widget.AppCompatImageButton
android:id="@id/exo_play_pause"
android:tint="@android:color/white"
android:scaleType="centerInside"
style="@style/ExoStyledControls.Button.Center.PlayPause"/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<androidx.appcompat.widget.AppCompatImageButton
android:id="@id/exo_play_pause"
android:tint="@android:color/white"
android:scaleType="centerInside"
android:layout_gravity="center"
style="@style/ExoStyledControls.Button.Center.PlayPause"/>

<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/loading_indicator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:indeterminate="true"/>
</FrameLayout>

<androidx.appcompat.widget.AppCompatImageButton
android:id="@id/exo_ffwd"
Expand Down

0 comments on commit 2e59e76

Please sign in to comment.