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, if (isOffline) OfflinePlayerService::class.java else OnlinePlayerService::class.java,
bundleOf() bundleOf()
) { ) {
if (_binding == null) {
it.sendCustomCommand(AbstractPlayerService.stopServiceCommand, Bundle.EMPTY)
it.release()
return@startMediaService
}
playerController = it playerController = it
handleServiceConnection() handleServiceConnection()
} }

View File

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