fix: crash when closing player before video started

This commit is contained in:
Bnyro 2024-11-19 10:33:04 +01:00
parent 994bebd8c4
commit 69f4c471c8
2 changed files with 18 additions and 4 deletions

View File

@ -93,6 +93,12 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
if (isOffline) OfflinePlayerService::class.java else OnlinePlayerService::class.java,
bundleOf()
) {
if (_binding == null) {
it.sendCustomCommand(AbstractPlayerService.stopServiceCommand, Bundle.EMPTY)
it.release()
return@startMediaService
}
playerController = it
handleServiceConnection()
}

View File

@ -458,6 +458,12 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
VideoOnlinePlayerService::class.java,
bundleOf(IntentData.playerData to playerData)
) {
if (_binding == null) {
playerController.sendCustomCommand(AbstractPlayerService.stopServiceCommand, Bundle.EMPTY)
playerController.release()
return@startMediaService
}
playerController = it
playerController.addListener(playerListener)
}
@ -847,11 +853,13 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
handler.removeCallbacksAndMessages(null)
playerController.removeListener(playerListener)
playerController.pause()
if (::playerController.isInitialized) {
playerController.removeListener(playerListener)
playerController.pause()
playerController.sendCustomCommand(AbstractPlayerService.stopServiceCommand, Bundle.EMPTY)
playerController.release()
playerController.sendCustomCommand(AbstractPlayerService.stopServiceCommand, Bundle.EMPTY)
playerController.release()
}
if (PlayerHelper.pipEnabled) {
// disable the auto PiP mode for SDK >= 32