Skip to content

Commit 021e438

Browse files
committed
refactor(player): Optimize code structure and clean up unused imports
1 parent af5bed9 commit 021e438

File tree

3 files changed

+21
-77
lines changed

3 files changed

+21
-77
lines changed

composeApp/src/commonMain/kotlin/com/jankinwu/fntv/client/ui/screen/PlayerScreen.kt

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ private fun callPlayRecord(
296296
}
297297
}
298298

299-
300-
301299
@OptIn(ExperimentalComposeUiApi::class)
302300
@Composable
303301
fun PlayerOverlay(
@@ -336,12 +334,6 @@ fun PlayerOverlay(
336334
}
337335
}
338336

339-
// val onSubtitleSettingsChanged: (SubtitleSettings) -> Unit = remember {
340-
// {
341-
// subtitleSettings = it
342-
// }
343-
// }
344-
345337
var isCursorVisible by remember { mutableStateOf(true) }
346338
var lastMouseMoveTime by remember { mutableLongStateOf(System.currentTimeMillis()) }
347339
val interactionSource = remember { MutableInteractionSource() }
@@ -551,62 +543,6 @@ fun PlayerOverlay(
551543

552544
LaunchedEffect(resetSubtitleState) {
553545
if (resetSubtitleState is UiState.Success) {
554-
// val cache = playingInfoCache
555-
// val startPos = mediaPlayer.getCurrentPositionMillis()
556-
// if (cache != null) {
557-
// // Re-fetch play link or use existing one?
558-
// // Usually resetSubtitle just changes state on server, we might need to re-request play link or just reuse.
559-
// // Assuming we can reuse existing playLink logic but re-evaluate subtitles.
560-
//
561-
// // We need to re-evaluate how to play based on new subtitle selection
562-
// val subtitleStream = cache.currentSubtitleStream
563-
// val playLink = cache.playLink ?: ""
564-
//
565-
// var extraFiles = MediaExtraFiles()
566-
// var actualPlayLink = playLink
567-
// var isM3u8 = false
568-
// var shouldStartPlayback = true
569-
//
570-
// if (subtitleStream != null) {
571-
// extraFiles = getMediaExtraFiles(subtitleStream, playLink)
572-
// }
573-
//
574-
// if (playLink.contains(".m3u8")) {
575-
// isM3u8 = true
576-
// // HLS logic
577-
// try {
578-
// // Check if it's an internal subtitle
579-
// if (subtitleStream != null && subtitleStream.isExternal == 0) {
580-
// // Reload HLS subtitle repository to fetch new segments
581-
// // hlsSubtitleUtil?.reload() // Removed reload() to avoid re-initialization conflict
582-
// // Don't restart playback for internal subtitles
583-
// if (cache.previousSubtitle?.isExternal == 0) {
584-
// shouldStartPlayback = false
585-
// }
586-
// }
587-
// } catch (e: Exception) {
588-
// logger.w("ResetSubtitle: Failed to parse m3u8: ${e.message}")
589-
// }
590-
// } else if (cache.isUseDirectLink) {
591-
// // Direct link logic (usually for external subtitles or non-HLS)
592-
// val (link, start) = getDirectPlayLink(
593-
// cache.currentVideoStream.mediaGuid,
594-
// startPos,
595-
// mp4Parser
596-
// )
597-
// actualPlayLink = link
598-
// }
599-
//
600-
//// if (shouldStartPlayback) {
601-
//// startPlayback(
602-
//// mediaPlayer,
603-
//// actualPlayLink,
604-
//// startPos,
605-
//// extraFiles,
606-
//// isM3u8
607-
//// )
608-
//// }
609-
// }
610546
mediaPViewModel.clearError()
611547
}
612548
}
@@ -2190,7 +2126,6 @@ private suspend fun resolvePlayLink(
21902126
}
21912127

21922128

2193-
21942129
private fun handlePlayerKeyEvent(
21952130
event: KeyEvent,
21962131
mediaPlayer: MediampPlayer,

composeApp/src/jvmMain/kotlin/com/jankinwu/fntv/client/main.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import androidx.compose.ui.window.WindowPosition
2121
import androidx.compose.ui.window.WindowState
2222
import androidx.compose.ui.window.application
2323
import androidx.compose.ui.window.rememberWindowState
24+
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
2425
import co.touchlab.kermit.Logger
2526
import com.jankinwu.fntv.client.data.network.apiModule
2627
import com.jankinwu.fntv.client.data.store.AppSettingsStore
@@ -44,7 +45,6 @@ import com.jankinwu.fntv.client.ui.screen.PlayerManager
4445
import com.jankinwu.fntv.client.ui.screen.PlayerOverlay
4546
import com.jankinwu.fntv.client.ui.screen.updateLoginHistory
4647
import com.jankinwu.fntv.client.ui.window.PipPlayerWindow
47-
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
4848
import com.jankinwu.fntv.client.utils.ComposeViewModelStoreOwner
4949
import com.jankinwu.fntv.client.utils.ConsoleLogWriter
5050
import com.jankinwu.fntv.client.utils.DesktopContext
@@ -68,12 +68,11 @@ import kotlinx.coroutines.flow.MutableStateFlow
6868
import kotlinx.coroutines.flow.debounce
6969
import kotlinx.coroutines.launch
7070
import org.jetbrains.compose.resources.painterResource
71-
import org.openani.mediamp.PlaybackState
7271
import org.koin.compose.KoinApplication
7372
import org.koin.compose.viewmodel.koinViewModel
73+
import org.openani.mediamp.PlaybackState
7474
import org.openani.mediamp.compose.rememberMediampPlayer
7575
import java.awt.Dimension
76-
import java.awt.Frame
7776
import java.io.File
7877
import java.util.concurrent.atomic.AtomicBoolean
7978

composeApp/src/jvmMain/kotlin/com/jankinwu/fntv/client/ui/window/PipPlayerWindow.kt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ fun PipPlayerWindow(
8383
val savedData = remember { PlayingSettingsStore.getPipWindowData() }
8484

8585
val audioLevelController = remember(mediaPlayer) { mediaPlayer.features[AudioLevelController] }
86-
val volume by audioLevelController?.volume?.collectAsState() ?: remember { mutableFloatStateOf(1f) }
86+
val volume by audioLevelController?.volume?.collectAsState() ?: remember {
87+
mutableFloatStateOf(
88+
1f
89+
)
90+
}
8791
var isVolumeControlHovered by remember { mutableStateOf(false) }
8892

8993
val hlsSubtitleUtil = remember(playingInfoCache) {
@@ -158,7 +162,10 @@ fun PipPlayerWindow(
158162
}
159163

160164
val windowState = rememberWindowState(
161-
position = if (savedData != null) WindowPosition(savedData.x.dp, savedData.y.dp) else WindowPosition.Aligned(Alignment.BottomEnd),
165+
position = if (savedData != null) WindowPosition(
166+
savedData.x.dp,
167+
savedData.y.dp
168+
) else WindowPosition.Aligned(Alignment.BottomEnd),
162169
width = if (savedData != null) savedData.width.dp else 320.dp,
163170
height = if (savedData != null) savedData.height.dp else 180.dp
164171
)
@@ -174,7 +181,8 @@ fun PipPlayerWindow(
174181

175182
// 确保有有效值
176183
val baseWidth = if (!currentWidth.isNaN() && currentWidth > 0f) currentWidth else 320f
177-
val baseHeight = if (!currentHeight.isNaN() && currentHeight > 0f) currentHeight else 180f
184+
val baseHeight =
185+
if (!currentHeight.isNaN() && currentHeight > 0f) currentHeight else 180f
178186

179187
val optimalSize = calculateOptimalPlayerWindowSize(
180188
videoStream,
@@ -289,12 +297,14 @@ fun PipPlayerWindow(
289297
BoxWithConstraints(
290298
modifier = Modifier.fillMaxSize()
291299
) {
292-
val playerScreenSize = remember { PlayingSettingsStore.getLastPlayerScreenSize() }
293-
val fontScaleRatio = if (playerScreenSize != null && playerScreenSize.width > 0) {
294-
maxWidth.value / playerScreenSize.width
295-
} else {
296-
maxWidth.value / 1280f
297-
}
300+
val playerScreenSize =
301+
remember { PlayingSettingsStore.getLastPlayerScreenSize() }
302+
val fontScaleRatio =
303+
if (playerScreenSize != null && playerScreenSize.width > 0) {
304+
maxWidth.value / playerScreenSize.width
305+
} else {
306+
maxWidth.value / 1280f
307+
}
298308

299309
SubtitleOverlay(
300310
subtitleCues = subtitleCues,

0 commit comments

Comments
 (0)