Skip to content

Commit fe0727e

Browse files
committed
fix(client): Fix volume control and data loading issues
1 parent dc03958 commit fe0727e

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import androidx.compose.ui.unit.dp
6262
import androidx.compose.ui.unit.sp
6363
import androidx.compose.ui.window.WindowPlacement
6464
import androidx.compose.ui.window.WindowState
65+
import kotlin.math.roundToInt
6566
import co.touchlab.kermit.Logger
6667
import com.fasterxml.jackson.databind.DeserializationFeature
6768
import com.fasterxml.jackson.databind.SerializationFeature
@@ -2111,7 +2112,7 @@ private fun handlePlayerKeyEvent(
21112112

21122113
Key.DirectionUp, Key.VolumeUp -> {
21132114
audioLevelController?.let {
2114-
val newVolume = (it.volume.value + 0.1f).coerceIn(0f, 1f)
2115+
val newVolume = (((it.volume.value + 0.1f) * 10).roundToInt() / 10f).coerceIn(0f, 1f)
21152116
it.setVolume(newVolume)
21162117
toastManager.showToast(
21172118
"当前音量:${(newVolume * 100).toInt()}%",
@@ -2125,7 +2126,7 @@ private fun handlePlayerKeyEvent(
21252126

21262127
Key.DirectionDown, Key.VolumeDown -> {
21272128
audioLevelController?.let {
2128-
val newVolume = (it.volume.value - 0.1f).coerceIn(0f, 1f)
2129+
val newVolume = (((it.volume.value - 0.1f) * 10).roundToInt() / 10f).coerceIn(0f, 1f)
21292130
it.setVolume(newVolume)
21302131
toastManager.showToast(
21312132
"当前音量:${(newVolume * 100).toInt()}%",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ private fun TvMiddleControls(
536536
val playMedia = rememberPlayMediaFunction(
537537
guid = guid,
538538
player = player,
539-
mediaGuid = playInfo.mediaGuid,
539+
// mediaGuid = playInfo.mediaGuid,
540540
// currentAudioGuid = currentAudioStream?.guid,
541541
// currentSubtitleGuid = currentSubtitleStream?.guid
542542
)

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ fun TvSeasonDetailScreen(
143143
episodeListViewModel.loadData(guid)
144144
}
145145
}
146-
LaunchedEffect(Unit) {
146+
LaunchedEffect(guid) {
147+
itemViewModel.clearError()
148+
playInfoViewModel.clearError()
149+
episodeListViewModel.clearError()
150+
personListViewModel.clearError()
151+
147152
itemViewModel.loadData(guid)
148153
playInfoViewModel.loadData(guid)
149154
episodeListViewModel.loadData(guid)
@@ -177,16 +182,16 @@ fun TvSeasonDetailScreen(
177182
LaunchedEffect(itemUiState) {
178183
if (itemUiState is UiState.Success) {
179184
itemData = (itemUiState as UiState.Success<ItemResponse>).data
185+
} else {
186+
itemData = null
180187
}
181188
}
182-
LaunchedEffect(playInfoUiState) {
183-
if (playInfoUiState is UiState.Success) {
184-
playInfoResponse = (playInfoUiState as UiState.Success<PlayInfoResponse>).data
185-
}
186-
}
189+
187190
LaunchedEffect(episodeListState) {
188191
if (episodeListState is UiState.Success) {
189192
episodeList = (episodeListState as UiState.Success<List<EpisodeListResponse>>).data
193+
} else {
194+
episodeList = emptyList()
190195
}
191196
}
192197

@@ -198,9 +203,12 @@ fun TvSeasonDetailScreen(
198203

199204
is UiState.Error -> {
200205
logger.e("message: ${(playInfoUiState as UiState.Error).message}")
206+
playInfoResponse = null
201207
}
202208

203-
else -> {}
209+
else -> {
210+
playInfoResponse = null
211+
}
204212
}
205213
}
206214

@@ -214,9 +222,14 @@ fun TvSeasonDetailScreen(
214222

215223
is UiState.Error -> {
216224
logger.e("message: ${(personListState as UiState.Error).message}")
225+
personList = emptyList()
226+
castScrollRowItemList = emptyList()
217227
}
218228

219-
else -> {}
229+
else -> {
230+
personList = emptyList()
231+
castScrollRowItemList = emptyList()
232+
}
220233
}
221234
}
222235

composeApp/src/commonMain/kotlin/com/jankinwu/fntv/client/utils/HlsSubtitleUtil.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class HlsSubtitleUtil(
3434
private val playLink: String,
3535
private val subtitleStream: SubtitleStream
3636
) {
37-
private val logger = Logger.withTag("HlsSubtitleRepository")
37+
private val logger = Logger.withTag("HlsSubtitleUtil")
3838

3939
private val segments = mutableListOf<SubtitleSegment>()
4040
private val cues = mutableListOf<SubtitleCue>()
@@ -132,12 +132,12 @@ class HlsSubtitleUtil(
132132
parseSegments(playlistContent)
133133
isInitialized = true
134134
}
135-
logger.i { "Initialized HLS subtitle repository with ${segments.size} segments" }
135+
logger.i { "Initialized HLS subtitle util with ${segments.size} segments" }
136136

137137
// 5. Immediately update for the current position
138138
update(startPositionMs)
139139
} catch (e: Exception) {
140-
logger.e(e) { "Failed to initialize HlsSubtitleRepository" }
140+
logger.e(e) { "Failed to initialize HlsSubtitleUtil" }
141141
}
142142
}
143143
}

composeApp/src/commonMain/kotlin/com/jankinwu/fntv/client/viewmodel/PersonListViewModel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package com.jankinwu.fntv.client.viewmodel
22

33
import androidx.lifecycle.viewModelScope
4-
import com.jankinwu.fntv.client.data.model.response.PersonList
54
import com.jankinwu.fntv.client.data.model.response.PersonListResponse
65
import com.jankinwu.fntv.client.data.network.impl.FnOfficialApiImpl
76
import kotlinx.coroutines.flow.MutableStateFlow
87
import kotlinx.coroutines.flow.StateFlow
98
import kotlinx.coroutines.flow.asStateFlow
109
import kotlinx.coroutines.launch
1110
import org.koin.java.KoinJavaComponent.inject
12-
import kotlin.getValue
1311

1412
class PersonListViewModel() : BaseViewModel() {
1513

@@ -26,4 +24,8 @@ class PersonListViewModel() : BaseViewModel() {
2624
}
2725
}
2826
}
27+
28+
fun clearError() {
29+
_uiState.value = UiState.Initial
30+
}
2931
}

0 commit comments

Comments
 (0)