From 33d23dcaf626bab16e52925d0449394739ca6186 Mon Sep 17 00:00:00 2001 From: Farhan Arshad Date: Thu, 19 Sep 2024 12:14:26 +0500 Subject: [PATCH] fix: Crash on CastContext instance when play services aren't available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Unable to get CastContext when Google Play services aren’t available, leads to the app crash. fixes: LEARNER-10231 --- .../unit/video/EncodedVideoUnitViewModel.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 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 84e6be219..a0aa110a6 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 @@ -24,6 +24,7 @@ import org.openedx.core.domain.model.VideoQuality import org.openedx.core.module.TranscriptManager import org.openedx.core.system.connection.NetworkConnection import org.openedx.core.system.notifier.CourseNotifier +import org.openedx.core.utils.Logger import org.openedx.course.data.repository.CourseRepository import org.openedx.course.presentation.CourseAnalytics import org.openedx.course.presentation.CourseAnalyticsKey @@ -48,7 +49,7 @@ class EncodedVideoUnitViewModel( transcriptManager, courseAnalytics ) { - + private val logger = Logger(TAG) private val _isVideoEnded = MutableLiveData(false) val isVideoEnded: LiveData get() = _isVideoEnded @@ -104,8 +105,10 @@ class EncodedVideoUnitViewModel( initPlayer() val executor = Executors.newSingleThreadExecutor() - CastContext.getSharedInstance(context, executor).result?.let { castContext -> + CastContext.getSharedInstance(context, executor).addOnSuccessListener { castContext -> castPlayer = CastPlayer(castContext) + }.addOnFailureListener { + logger.e(it, true) } } @@ -185,4 +188,8 @@ class EncodedVideoUnitViewModel( CourseAnalyticsKey.NATIVE.key } } + + private companion object { + private const val TAG = "EncodedVideoUnitViewModel" + } }