diff --git a/app/src/main/java/org/oppia/android/app/player/audio/AudioViewModel.kt b/app/src/main/java/org/oppia/android/app/player/audio/AudioViewModel.kt index 954be314639..53e1f47b2d8 100644 --- a/app/src/main/java/org/oppia/android/app/player/audio/AudioViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/audio/AudioViewModel.kt @@ -1,5 +1,6 @@ package org.oppia.android.app.player.audio +import android.util.Log import androidx.databinding.ObservableBoolean import androidx.databinding.ObservableField import androidx.lifecycle.LiveData @@ -67,12 +68,15 @@ class AudioViewModel @Inject constructor( } fun setStateAndExplorationId(newState: State?, id: String?) { - if (newState != null && id != null) { - state = newState - explorationId = id + if (newState == null || id == null) { + Log.e("AudioViewModel", "Failed to set state or id - parameters are null") + return } + state = newState + explorationId = id } + fun loadMainContentAudio(allowAutoPlay: Boolean, reloadingContent: Boolean) { hasFeedback = false loadAudio(contentId = null, allowAutoPlay, reloadingContent) @@ -90,8 +94,11 @@ 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 + if (!::state.isInitialized || !::explorationId.isInitialized) { + Log.w("AudioViewModel", "Cannot load audio: state or explorationId is not initialized.") + return + } + val targetContentId = contentId ?: state.content.contentId val voiceoverMapping = state.recordedVoiceoversMap[targetContentId] ?: VoiceoverMapping.getDefaultInstance()