Skip to content

Commit

Permalink
fix: viewModelScope keeping some a coroutine alive after PlayerActivi…
Browse files Browse the repository at this point in the history
…ty is destroyed

oh and also fix crash when exiting the player
  • Loading branch information
abdallahmehiz committed Nov 9, 2024
1 parent c1e5a8b commit 1d0c998
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ class PlayerActivity : AppCompatActivity() {
}

internal fun event(eventId: Int) {
if (player.isExiting) return
when (eventId) {
MPVLib.mpvEventId.MPV_EVENT_FILE_LOADED -> {
fileName = getFileName(intent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import dev.vivvvek.seeker.Segment
import `is`.xyz.mpv.MPVLib
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand Down Expand Up @@ -542,6 +543,11 @@ class PlayerViewModel(

MPVLib.command(arrayOf("load-script", tempFile.absolutePath))
}

override fun onCleared() {
super.onCleared()
viewModelScope.cancel()
}
}

data class Track(
Expand Down

0 comments on commit 1d0c998

Please sign in to comment.