Skip to content

Commit

Permalink
fix: Crash on CastContext instance when play services aren't available (
Browse files Browse the repository at this point in the history
#53)

- Unable to get CastContext when Google Play services aren’t available, leads to the app crash.

fixes: LEARNER-10231
  • Loading branch information
farhan-arshad-dev authored Sep 19, 2024
1 parent 7c8f646 commit d16df3f
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,7 +49,7 @@ class EncodedVideoUnitViewModel(
transcriptManager,
courseAnalytics
) {

private val logger = Logger(TAG)
private val _isVideoEnded = MutableLiveData(false)
val isVideoEnded: LiveData<Boolean>
get() = _isVideoEnded
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -185,4 +188,8 @@ class EncodedVideoUnitViewModel(
CourseAnalyticsKey.NATIVE.key
}
}

private companion object {
private const val TAG = "EncodedVideoUnitViewModel"
}
}

0 comments on commit d16df3f

Please sign in to comment.