mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Fixes MPV crash when playing next up (#772)
## Description Ensure that MPV is always destroyed before being initialized again. Also, now creating a new player is only done when switching backends which means faster, more efficient playing the next up. ### Related issues Fixes #766
This commit is contained in:
parent
7b8f5c3e63
commit
03871579f5
3 changed files with 29 additions and 28 deletions
|
|
@ -219,7 +219,9 @@ class PlaybackViewModel
|
|||
PlayerBackend.PREFER_MPV -> if (isHdr) PlayerBackend.EXO_PLAYER else PlayerBackend.MPV
|
||||
}
|
||||
|
||||
Timber.i("Selected backend: %s", playerBackend)
|
||||
Timber.d("Selected backend: %s", playerBackend)
|
||||
if (currentPlayer.value?.backend != playerBackend) {
|
||||
Timber.i("Switching player backend to %s", playerBackend)
|
||||
withContext(Dispatchers.Main) {
|
||||
disconnectPlayer()
|
||||
}
|
||||
|
|
@ -232,6 +234,8 @@ class PlaybackViewModel
|
|||
currentPlayer.update {
|
||||
PlayerState(player, playerBackend)
|
||||
}
|
||||
configurePlayer()
|
||||
}
|
||||
}
|
||||
|
||||
private fun configurePlayer() {
|
||||
|
|
@ -429,7 +433,6 @@ class PlaybackViewModel
|
|||
|
||||
// Create the correct player for the media
|
||||
createPlayer(videoStream?.hdr == true)
|
||||
configurePlayer()
|
||||
|
||||
val subtitleStreams =
|
||||
mediaSource.mediaStreams
|
||||
|
|
|
|||
|
|
@ -39,17 +39,9 @@ object MPVLib {
|
|||
|
||||
external fun create(appctx: Context)
|
||||
|
||||
fun initialize() {
|
||||
synchronized(this) { init() }
|
||||
}
|
||||
external fun init()
|
||||
|
||||
private external fun init()
|
||||
|
||||
fun tearDown() {
|
||||
synchronized(this) { destroy() }
|
||||
}
|
||||
|
||||
private external fun destroy()
|
||||
external fun destroy()
|
||||
|
||||
external fun attachSurface(surface: Surface)
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,8 @@ class MpvPlayer(
|
|||
SurfaceHolder.Callback {
|
||||
companion object {
|
||||
private const val DEBUG = false
|
||||
|
||||
private val initLock = Any()
|
||||
}
|
||||
|
||||
private var surface: Surface? = null
|
||||
|
|
@ -131,7 +133,7 @@ class MpvPlayer(
|
|||
MPVLib.setOptionString("demuxer-max-back-bytes", "${cacheMegs * 1024 * 1024}")
|
||||
|
||||
Timber.v("Initializing MPVLib")
|
||||
MPVLib.initialize()
|
||||
MPVLib.init()
|
||||
|
||||
MPVLib.setOptionString("force-window", "no")
|
||||
MPVLib.setOptionString("idle", "yes")
|
||||
|
|
@ -1086,17 +1088,21 @@ class MpvPlayer(
|
|||
}
|
||||
|
||||
MpvCommand.INITIALIZE -> {
|
||||
synchronized(initLock) {
|
||||
init()
|
||||
}
|
||||
}
|
||||
|
||||
MpvCommand.DESTROY -> {
|
||||
clearVideoSurfaceView(null)
|
||||
synchronized(initLock) {
|
||||
MPVLib.setPropertyBoolean("pause", true)
|
||||
MPVLib.removeLogObserver(mpvLogger)
|
||||
MPVLib.tearDown()
|
||||
MPVLib.destroy()
|
||||
Timber.d("MPVLib destroyed")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun MPVLib.setPropertyColor(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue