Skip to content

Commit

Permalink
fix: player control & player background
Browse files Browse the repository at this point in the history
  • Loading branch information
muedsa committed Jul 22, 2024
1 parent 100ea04 commit 7d9859b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import android.view.Gravity
import android.widget.FrameLayout
import androidx.activity.compose.BackHandler
import androidx.annotation.OptIn
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.viewinterop.AndroidView
import androidx.media3.common.Player
Expand Down Expand Up @@ -77,7 +79,10 @@ fun DanmakuVideoPlayer(
}

DisposableEffect(
Box(modifier = Modifier.fillMaxSize()) {
Box(modifier = Modifier
.background(Color.Black)
.fillMaxSize()
) {
AndroidView(factory = {
PlayerView(context).apply {
hideController()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import com.muedsa.compose.tv.widget.OutlinedIconBox
import kotlinx.coroutines.delay
import java.util.Date
import java.util.Locale
import kotlin.time.Duration.Companion.microseconds
import kotlin.time.Duration.Companion.seconds
import kotlin.time.DurationUnit
import kotlin.time.toDuration
Expand Down Expand Up @@ -239,18 +240,17 @@ fun PlayerControl(
@Composable
fun PlayerProgressIndicator(player: Player) {
val dateTimeFormat = remember { SimpleDateFormat.getDateTimeInstance() }
val systemStr = dateTimeFormat.format(Date())
val currentStr =
if (player.duration > 0L) durationToString(player.currentPosition) else "--:--:--"
val totalStr = if (player.duration > 0L) durationToString(player.duration) else "--:--:--"
var systemStr by remember { mutableStateOf("--/--/-- --:--:--") }
var currentStr by remember { mutableStateOf("--:--:--") }
var totalStr by remember { mutableStateOf("--:--:--") }
Column(
modifier = Modifier.fillMaxWidth(),
) {
if (player.duration > 0L) {
LinearProgressIndicator(
progress = { player.currentPosition.toFloat() / player.duration },
modifier = Modifier.fillMaxWidth(),
)
) { }
} else {
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
}
Expand All @@ -264,6 +264,14 @@ fun PlayerProgressIndicator(player: Player) {
)
}

LaunchedEffect(key1 = Unit) {
while (true) {
systemStr = dateTimeFormat.format(Date())
currentStr = if (player.duration > 0L) durationToString(player.currentPosition) else "--:--:--"
totalStr = if (player.duration > 0L) durationToString(player.duration) else "--:--:--"
delay(100.microseconds)
}
}
}

fun groupTypeToString(group: Tracks.Group): String {
Expand Down
24 changes: 7 additions & 17 deletions app/src/main/kotlin/com/muedsa/jcytv/PlaybackActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ package com.muedsa.jcytv
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Surface
import androidx.tv.material3.SurfaceDefaults
import com.muedsa.compose.tv.theme.TvTheme
import com.muedsa.compose.tv.useLocalErrorMsgBoxController
Expand Down Expand Up @@ -52,19 +48,13 @@ class PlaybackActivity : ComponentActivity() {
}
errorMsgBoxController.error("再次点击返回键退出")
}
Surface(
modifier = Modifier.fillMaxSize(),
shape = RectangleShape,

) {
PlaybackScreen(
aid = aid,
episodeTitle = episodeTitle,
mediaUrl = mediaUrl,
danEpisodeId = episodeId,
backListeners = backListeners
)
}
PlaybackScreen(
aid = aid,
episodeTitle = episodeTitle,
mediaUrl = mediaUrl,
danEpisodeId = episodeId,
backListeners = backListeners
)
}
}
}
Expand Down

0 comments on commit 7d9859b

Please sign in to comment.