mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
Merge pull request #6784 from Bnyro/master
fix: crash when starting other video
This commit is contained in:
commit
952c9adc10
@ -6,6 +6,7 @@ import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.annotation.OptIn
|
||||
import androidx.core.app.ServiceCompat
|
||||
import androidx.core.os.postDelayed
|
||||
import androidx.media3.common.C
|
||||
import androidx.media3.common.PlaybackException
|
||||
import androidx.media3.common.Player
|
||||
@ -293,29 +294,36 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
PlayingQueue.resetToDefaults()
|
||||
// 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()
|
||||
|
||||
saveWatchPosition()
|
||||
saveWatchPosition()
|
||||
|
||||
notificationProvider = null
|
||||
watchPositionTimer.destroy()
|
||||
notificationProvider = null
|
||||
watchPositionTimer.destroy()
|
||||
|
||||
handler.removeCallbacksAndMessages(null)
|
||||
handler.removeCallbacksAndMessages(null)
|
||||
|
||||
runCatching {
|
||||
exoPlayer?.stop()
|
||||
exoPlayer?.release()
|
||||
runCatching {
|
||||
exoPlayer?.stop()
|
||||
exoPlayer?.release()
|
||||
}
|
||||
|
||||
kotlin.runCatching {
|
||||
mediaLibrarySession?.release()
|
||||
mediaLibrarySession = null
|
||||
}
|
||||
|
||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||
stopSelf()
|
||||
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
kotlin.runCatching {
|
||||
mediaLibrarySession?.release()
|
||||
mediaLibrarySession = null
|
||||
}
|
||||
|
||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||
stopSelf()
|
||||
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
fun isVideoIdInitialized() = this::videoId.isInitialized
|
||||
|
@ -232,6 +232,8 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
|
||||
private fun killFragment() {
|
||||
playerController?.sendCustomCommand(AbstractPlayerService.stopServiceCommand, Bundle.EMPTY)
|
||||
playerController?.release()
|
||||
playerController = null
|
||||
|
||||
viewModel.isFullscreen.value = false
|
||||
binding.playerMotionLayout.transitionToEnd()
|
||||
|
@ -851,6 +851,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
playerController.pause()
|
||||
|
||||
playerController.sendCustomCommand(AbstractPlayerService.stopServiceCommand, Bundle.EMPTY)
|
||||
playerController.release()
|
||||
|
||||
if (PlayerHelper.pipEnabled) {
|
||||
// disable the auto PiP mode for SDK >= 32
|
||||
|
Loading…
x
Reference in New Issue
Block a user