Skip to content

Commit

Permalink
修复弹幕暂停
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Apr 4, 2024
1 parent 3740988 commit e6b8246
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import me.him188.ani.app.torrent.TorrentManager
import me.him188.ani.app.ui.foundation.AbstractViewModel
import me.him188.ani.app.ui.foundation.HasBackgroundScope
import me.him188.ani.app.ui.foundation.launchInBackground
import me.him188.ani.app.ui.foundation.launchInMain
import me.him188.ani.app.videoplayer.PlayerState
import me.him188.ani.app.videoplayer.PlayerStateFactory
import me.him188.ani.app.videoplayer.TorrentVideoSource
Expand Down Expand Up @@ -349,7 +350,7 @@ private class EpisodeViewModelImpl(
override val danmakuHostState: DanmakuHostState = DanmakuHostState()

init {
launchInBackground {
launchInMain { // state changes must be in main thread
playerState.state.collect {
if (it.isPlaying) {
danmakuHostState.resume()
Expand Down
2 changes: 1 addition & 1 deletion app/shared/video-player/androidMain/PlayerState.android.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ internal class ExoPlayerState @UiThread constructor(
}

override fun onPlaybackStateChanged(playbackState: Int) {
updateVideoProperties()
when (playbackState) {
Player.STATE_BUFFERING -> state.value = PlaybackState.PAUSED_BUFFERING
Player.STATE_ENDED -> state.value = PlaybackState.FINISHED
Player.STATE_IDLE -> state.value = PlaybackState.READY
Player.STATE_READY -> state.value = PlaybackState.READY
}
updateVideoProperties()
}

override fun onIsPlayingChanged(isPlaying: Boolean) {
Expand Down
3 changes: 3 additions & 0 deletions danmaku/ui/commonMain/DanmakuHost.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.him188.ani.danmaku.ui

import androidx.annotation.UiThread
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -30,11 +31,13 @@ interface DanmakuHostState {
/**
* Pauses the movement of danmaku.
*/
@UiThread
fun pause()

/**
* Resumes the movement of danmaku. Danmaku will continue to move from where it was paused.
*/
@UiThread
fun resume()
}

Expand Down

0 comments on commit e6b8246

Please sign in to comment.