Skip to content

Commit

Permalink
fix: lateinit property of questions and answers not initialised
Browse files Browse the repository at this point in the history
  • Loading branch information
oyeraghib committed Apr 30, 2024
1 parent c12b398 commit db53e73
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class CardMediaPlayer : Closeable {
*/
private suspend fun playAllSoundsInternal(cardSide: CardSide, isAutomaticPlayback: Boolean) {
if (!isEnabled) return
if (!isQuestionsAnswersInitialised()) return
val soundList = when (cardSide) {
CardSide.QUESTION -> questions
CardSide.ANSWER -> answers
Expand Down Expand Up @@ -291,8 +292,13 @@ class CardMediaPlayer : Closeable {
return@withContext true
}

fun hasSounds(displayAnswer: Boolean): Boolean =
if (displayAnswer) answers.any() else questions.any()
fun hasSounds(displayAnswer: Boolean): Boolean {
if (!isQuestionsAnswersInitialised()) {
// Questions or Answers property not initialized, return false
return false
}
return if (displayAnswer) answers.any() else questions.any()
}

/**
* Plays all sounds for the current side, calling [onSoundGroupCompleted] when completed
Expand Down Expand Up @@ -343,6 +349,10 @@ class CardMediaPlayer : Closeable {
soundTagPlayer.videoPlayer.onVideoPaused()
}

private fun isQuestionsAnswersInitialised(): Boolean {
return (this::questions.isInitialized || this::answers.isInitialized)
}

companion object {
const val TTS_PLAYER_TIMEOUT_MS = 2_500L

Expand Down

0 comments on commit db53e73

Please sign in to comment.