Merge pull request #6784 from Bnyro/master

fix: crash when starting other video
This commit is contained in:
Bnyro 2024-11-19 10:24:28 +01:00 committed by GitHub
commit 952c9adc10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 18 deletions

View File

@ -6,6 +6,7 @@ import android.os.Handler
import android.os.Looper import android.os.Looper
import androidx.annotation.OptIn import androidx.annotation.OptIn
import androidx.core.app.ServiceCompat import androidx.core.app.ServiceCompat
import androidx.core.os.postDelayed
import androidx.media3.common.C import androidx.media3.common.C
import androidx.media3.common.PlaybackException import androidx.media3.common.PlaybackException
import androidx.media3.common.Player import androidx.media3.common.Player
@ -293,6 +294,12 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
} }
override fun onDestroy() { override fun onDestroy() {
// wait for a short time before killing the mediaSession
// as the playerController must be released before we finish the session
// otherwise there would be a
// java.lang.SecurityException: Session rejected the connection request.
// because there can't be two active playerControllers at the same time.
handler.postDelayed(50) {
PlayingQueue.resetToDefaults() PlayingQueue.resetToDefaults()
saveWatchPosition() saveWatchPosition()
@ -317,6 +324,7 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
super.onDestroy() super.onDestroy()
} }
}
fun isVideoIdInitialized() = this::videoId.isInitialized fun isVideoIdInitialized() = this::videoId.isInitialized

View File

@ -232,6 +232,8 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
private fun killFragment() { private fun killFragment() {
playerController?.sendCustomCommand(AbstractPlayerService.stopServiceCommand, Bundle.EMPTY) playerController?.sendCustomCommand(AbstractPlayerService.stopServiceCommand, Bundle.EMPTY)
playerController?.release()
playerController = null
viewModel.isFullscreen.value = false viewModel.isFullscreen.value = false
binding.playerMotionLayout.transitionToEnd() binding.playerMotionLayout.transitionToEnd()

View File

@ -851,6 +851,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
playerController.pause() playerController.pause()
playerController.sendCustomCommand(AbstractPlayerService.stopServiceCommand, Bundle.EMPTY) playerController.sendCustomCommand(AbstractPlayerService.stopServiceCommand, Bundle.EMPTY)
playerController.release()
if (PlayerHelper.pipEnabled) { if (PlayerHelper.pipEnabled) {
// disable the auto PiP mode for SDK >= 32 // disable the auto PiP mode for SDK >= 32