Skip to content

Commit

Permalink
Fix crash in AudioViewModel by initializing state variables
Browse files Browse the repository at this point in the history
  • Loading branch information
TanishMoral11 committed Oct 28, 2024
1 parent 2301a52 commit 0dc284f
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ class AudioViewModel @Inject constructor(
processPlayStatusLiveData()
}

fun setStateAndExplorationId(newState: State, id: String) {
state = newState
explorationId = id
fun setStateAndExplorationId(newState: State?, id: String?) {
if (newState != null && id != null) {
state = newState
explorationId = id
}
}

fun loadMainContentAudio(allowAutoPlay: Boolean, reloadingContent: Boolean) {
Expand All @@ -88,6 +90,8 @@ class AudioViewModel @Inject constructor(
* @param allowAutoPlay If false, audio is guaranteed not to be autoPlayed.
*/
private fun loadAudio(contentId: String?, allowAutoPlay: Boolean, reloadingMainContent: Boolean) {
// Check if 'state' is initialized before proceeding.
if (!::state.isInitialized) return
val targetContentId = contentId ?: state.content.contentId
val voiceoverMapping =
state.recordedVoiceoversMap[targetContentId] ?: VoiceoverMapping.getDefaultInstance()
Expand Down

0 comments on commit 0dc284f

Please sign in to comment.