Skip to content

Commit

Permalink
Fix #958 安卓全屏后调节亮度无效
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Sep 25, 2024
1 parent 10ea2e9 commit f98a5ba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
22 changes: 20 additions & 2 deletions app/shared/src/commonMain/kotlin/ui/subject/episode/EpisodePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ import me.him188.ani.app.data.source.danmaku.protocol.DanmakuInfo
import me.him188.ani.app.data.source.danmaku.protocol.DanmakuLocation
import me.him188.ani.app.navigation.LocalNavigator
import me.him188.ani.app.platform.LocalContext
import me.him188.ani.app.platform.features.StreamType
import me.him188.ani.app.platform.features.getComponentAccessors
import me.him188.ani.app.tools.rememberUiMonoTasker
import me.him188.ani.app.ui.external.placeholder.placeholder
import me.him188.ani.app.ui.foundation.ImageViewer
Expand Down Expand Up @@ -117,6 +119,8 @@ import me.him188.ani.app.ui.subject.episode.notif.VideoNotifEffect
import me.him188.ani.app.ui.subject.episode.video.VideoDanmakuState
import me.him188.ani.app.ui.subject.episode.video.topbar.EpisodePlayerTitle
import me.him188.ani.app.videoplayer.ui.VideoControllerState
import me.him188.ani.app.videoplayer.ui.guesture.NoOpLevelController
import me.him188.ani.app.videoplayer.ui.guesture.asLevelController
import me.him188.ani.app.videoplayer.ui.progress.PlayerControllerDefaults
import me.him188.ani.app.videoplayer.ui.progress.PlayerControllerDefaults.randomDanmakuPlaceholder
import me.him188.ani.app.videoplayer.ui.progress.rememberMediaProgressSliderState
Expand Down Expand Up @@ -587,6 +591,12 @@ private fun EpisodeVideo(
)
val scope = rememberCoroutineScope()

// 必须在 UI 里, 跟随 context 变化. 否则 #958
val platformComponents by remember {
derivedStateOf {
context.getComponentAccessors()
}
}
EpisodeVideoImpl(
vm.playerState,
expanded = expanded,
Expand Down Expand Up @@ -658,8 +668,16 @@ private fun EpisodeVideo(
mediaSourceResultsPresentation = vm.mediaSourceResultsPresentation,
episodeSelectorState = vm.episodeSelectorState,
mediaSourceInfoProvider = vm.mediaSourceInfoProvider,
audioController = vm.audioController,
brightnessController = vm.brightnessController,
audioController = remember {
derivedStateOf {
platformComponents.audioManager?.asLevelController(StreamType.MUSIC) ?: NoOpLevelController
}
}.value,
brightnessController = remember {
derivedStateOf {
platformComponents.brightnessManager?.asLevelController() ?: NoOpLevelController
}
}.value,
leftBottomTips = {
AnimatedVisibility(
visible = vm.playerSkipOpEdState.showSkipTips,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.app.ui.subject.episode

import androidx.annotation.UiThread
Expand Down Expand Up @@ -58,9 +67,6 @@ import me.him188.ani.app.data.source.media.selector.autoSelect
import me.him188.ani.app.data.source.media.selector.eventHandling
import me.him188.ani.app.data.source.session.AuthState
import me.him188.ani.app.platform.Context
import me.him188.ani.app.platform.features.PlatformComponentAccessors
import me.him188.ani.app.platform.features.StreamType
import me.him188.ani.app.platform.features.getComponentAccessors
import me.him188.ani.app.tools.caching.ContentPolicy
import me.him188.ani.app.ui.comment.BangumiCommentSticker
import me.him188.ani.app.ui.foundation.AbstractViewModel
Expand Down Expand Up @@ -94,9 +100,6 @@ import me.him188.ani.app.ui.subject.episode.video.VideoDanmakuStateImpl
import me.him188.ani.app.ui.subject.episode.video.sidesheet.EpisodeSelectorState
import me.him188.ani.app.videoplayer.ui.ControllerVisibility
import me.him188.ani.app.videoplayer.ui.VideoControllerState
import me.him188.ani.app.videoplayer.ui.guesture.LevelController
import me.him188.ani.app.videoplayer.ui.guesture.NoOpLevelController
import me.him188.ani.app.videoplayer.ui.guesture.asLevelController
import me.him188.ani.app.videoplayer.ui.state.PlaybackState
import me.him188.ani.app.videoplayer.ui.state.PlayerState
import me.him188.ani.app.videoplayer.ui.state.PlayerStateFactory
Expand Down Expand Up @@ -173,10 +176,6 @@ abstract class EpisodeViewModel : AbstractViewModel(), HasBackgroundScope {

abstract val mediaSourceInfoProvider: MediaSourceInfoProvider

abstract val audioController: LevelController
abstract val brightnessController: LevelController


// Video
abstract val videoControllerState: VideoControllerState
abstract val videoScaffoldConfig: VideoScaffoldConfig
Expand Down Expand Up @@ -336,17 +335,6 @@ private class EpisodeViewModelImpl(
getSourceInfoFlow = { mediaSourceManager.infoFlowByMediaSourceId(it) },
)

private val platformComponentAccessors: PlatformComponentAccessors = context.getComponentAccessors()

override val audioController: LevelController by lazy {
platformComponentAccessors.audioManager?.asLevelController(
StreamType.MUSIC,
) ?: NoOpLevelController
}
override val brightnessController: LevelController by lazy {
platformComponentAccessors.brightnessManager?.asLevelController() ?: NoOpLevelController
}

override val mediaSelectorPresentation: MediaSelectorPresentation =
MediaSelectorPresentation(mediaSelector, mediaSourceInfoProvider, backgroundScope.coroutineContext)

Expand Down

0 comments on commit f98a5ba

Please sign in to comment.