Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
kotlin.runCatching {
mediaLibrarySession?.release()
mediaLibrarySession = null
}

ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
stopSelf()
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
stopSelf()

super.onDestroy()
super.onDestroy()
}
}

fun isVideoIdInitialized() = this::videoId.isInitialized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading