Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Crash on CastContext instance when play services aren't available #53

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
Loading