From 6c4cfe9d22e6fb8f1da87cf780ffe3aa5245147c Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 19 Dec 2023 13:26:00 +0100 Subject: [PATCH] fix: crash when trying to get video transcription in main thread (#170) --- .../course/presentation/unit/video/VideoUnitViewModel.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/course/src/main/java/org/openedx/course/presentation/unit/video/VideoUnitViewModel.kt b/course/src/main/java/org/openedx/course/presentation/unit/video/VideoUnitViewModel.kt index 1ceb8f8c6..bd87ec477 100644 --- a/course/src/main/java/org/openedx/course/presentation/unit/video/VideoUnitViewModel.kt +++ b/course/src/main/java/org/openedx/course/presentation/unit/video/VideoUnitViewModel.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch @@ -74,9 +75,9 @@ open class VideoUnitViewModel( } fun downloadSubtitles() { - viewModelScope.launch { + viewModelScope.launch(Dispatchers.IO) { transcriptManager.downloadTranscriptsForVideo(getTranscriptUrl())?.let { result -> - _transcriptObject.value = result + _transcriptObject.postValue(result) timeList = result.captions.values.toList() .map { it.start.mseconds.toLong() } }