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? {