From 185fdae12ef16e0c1f6dfeb652d8a604b6960a01 Mon Sep 17 00:00:00 2001 From: "omer.habib" Date: Tue, 27 Aug 2024 13:04:40 +0500 Subject: [PATCH] fix: Casting method update + crash fix - Update casting method for initialization - Release casting onPause() --- .../unit/video/EncodedVideoUnitViewModel.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/course/src/main/java/org/openedx/course/presentation/unit/video/EncodedVideoUnitViewModel.kt b/course/src/main/java/org/openedx/course/presentation/unit/video/EncodedVideoUnitViewModel.kt index dec6f70e9..84e6be219 100644 --- a/course/src/main/java/org/openedx/course/presentation/unit/video/EncodedVideoUnitViewModel.kt +++ b/course/src/main/java/org/openedx/course/presentation/unit/video/EncodedVideoUnitViewModel.kt @@ -104,10 +104,8 @@ class EncodedVideoUnitViewModel( initPlayer() val executor = Executors.newSingleThreadExecutor() - CastContext.getSharedInstance(context, executor).addOnCompleteListener { - it.result?.let { castContext -> - castPlayer = CastPlayer(castContext) - } + CastContext.getSharedInstance(context, executor).result?.let { castContext -> + castPlayer = CastPlayer(castContext) } } @@ -119,8 +117,12 @@ class EncodedVideoUnitViewModel( override fun onPause(owner: LifecycleOwner) { super.onPause(owner) - exoPlayer?.removeListener(exoPlayerListener) - exoPlayer?.pause() + if (isCastActive) { + getActivePlayer()?.release() + } else { + exoPlayer?.removeListener(exoPlayerListener) + exoPlayer?.pause() + } } fun getActivePlayer(): Player? {