mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20: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 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,29 +294,36 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
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
|
notificationProvider = null
|
||||||
watchPositionTimer.destroy()
|
watchPositionTimer.destroy()
|
||||||
|
|
||||||
handler.removeCallbacksAndMessages(null)
|
handler.removeCallbacksAndMessages(null)
|
||||||
|
|
||||||
runCatching {
|
runCatching {
|
||||||
exoPlayer?.stop()
|
exoPlayer?.stop()
|
||||||
exoPlayer?.release()
|
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
|
fun isVideoIdInitialized() = this::videoId.isInitialized
|
||||||
|
@ -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()
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user