Skip to content
Merged
Show file tree
Hide file tree
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
68 changes: 34 additions & 34 deletions AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ abstract class AbstractFlashcardViewer :
"AbstractFlashcardViewer:: OK button pressed to delete note %d",
currentCard!!.nid,
)
launchCatchingTask { cardMediaPlayer.stopSounds() }
launchCatchingTask { cardMediaPlayer.stop() }
deleteNoteWithoutConfirmation()
}
negativeButton(R.string.dialog_cancel)
Expand Down Expand Up @@ -845,7 +845,7 @@ abstract class AbstractFlashcardViewer :
}
// Temporarily sets the answer indicator dots appearing below the toolbar
previousAnswerIndicator?.displayAnswerIndicator(ease)
cardMediaPlayer.stopSounds()
cardMediaPlayer.stop()
currentEase = ease

answerCardInner(ease)
Expand Down Expand Up @@ -1286,15 +1286,15 @@ abstract class AbstractFlashcardViewer :
}
}

private suspend fun automaticAnswerShouldWaitForAudio(): Boolean =
private suspend fun automaticAnswerShouldWaitForMedia(): Boolean =
withCol {
decks.configDictForDeckId(currentCard!!.did).waitForAudio
}

internal inner class ReadTextListener : ReadText.ReadTextListener {
override fun onDone(playedSide: CardSide?) {
Timber.d("done reading text")
this@AbstractFlashcardViewer.onSoundGroupCompleted()
this@AbstractFlashcardViewer.onMediaGroupCompleted()
}
}

Expand All @@ -1315,7 +1315,7 @@ abstract class AbstractFlashcardViewer :
val content = cardRenderContext!!.renderCard(getColUnsafe, currentCard!!, SingleCardSide.FRONT)
automaticAnswer.onDisplayQuestion()
launchCatchingTask {
if (!automaticAnswerShouldWaitForAudio()) {
if (!automaticAnswerShouldWaitForMedia()) {
automaticAnswer.scheduleAutomaticDisplayAnswer()
}
}
Expand Down Expand Up @@ -1361,7 +1361,7 @@ abstract class AbstractFlashcardViewer :
val answerContent = cardRenderContext!!.renderCard(getColUnsafe, currentCard!!, SingleCardSide.BACK)
automaticAnswer.onDisplayAnswer()
launchCatchingTask {
if (!automaticAnswerShouldWaitForAudio()) {
if (!automaticAnswerShouldWaitForMedia()) {
automaticAnswer.scheduleAutomaticDisplayQuestion()
}
}
Expand Down Expand Up @@ -1423,36 +1423,36 @@ abstract class AbstractFlashcardViewer :
Timber.d("updateCard()")
// TODO: This doesn't need to be blocking
runBlocking {
cardMediaPlayer.loadCardSounds(currentCard!!)
cardMediaPlayer.loadCardAvTags(currentCard!!)
}
cardContent = content.html
fillFlashcard()
playSounds(false) // Play sounds if appropriate
playMedia(false) // Play media if appropriate
}

/**
* Plays sounds (or TTS, if configured) for currently shown side of card.
* Plays media (or TTS, if configured) for currently shown side of card.
*
* @param doAudioReplay indicates an anki desktop-like replay call is desired, whose behavior is identical to
* @param doMediaReplay indicates an anki desktop-like replay call is desired, whose behavior is identical to
* pressing the keyboard shortcut R on the desktop
*/
@NeedsTest("audio is not played if opExecuted occurs when viewer is in the background")
protected open fun playSounds(doAudioReplay: Boolean) {
@NeedsTest("media is not played if opExecuted occurs when viewer is in the background")
protected open fun playMedia(doMediaReplay: Boolean) {
// this can occur due to OpChanges when the viewer is on another screen
if (!this.lifecycle.currentState.isAtLeast(RESUMED)) {
Timber.w("sounds are not played as the activity is inactive")
Timber.w("media is not played as the activity is inactive")
return
}
if (!cardMediaPlayer.config.autoplay && !doAudioReplay) return
// Use TTS if TTS preference enabled and no other sound source
val useTTS = tts.enabled && !cardMediaPlayer.hasSounds(displayAnswer)
// We need to play the sounds from the proper side of the card
if (!cardMediaPlayer.config.autoplay && !doMediaReplay) return
// Use TTS if TTS preference enabled and no other media source
val useTTS = tts.enabled && !cardMediaPlayer.hasMedia(displayAnswer)
// We need to play the media from the proper side of the card
if (!useTTS) {
launchCatchingTask {
val side = if (displayAnswer) SingleCardSide.BACK else SingleCardSide.FRONT
when (doAudioReplay) {
true -> cardMediaPlayer.replayAllSounds(side)
false -> cardMediaPlayer.playAllSounds(side)
when (doMediaReplay) {
true -> cardMediaPlayer.replayAll(side)
false -> cardMediaPlayer.playAll(side)
}
}
return
Expand All @@ -1462,7 +1462,7 @@ abstract class AbstractFlashcardViewer :
// Text to speech is in effect here
// If the question is displayed or if the question should be replayed, read the question
if (ttsInitialized) {
if (!displayAnswer || doAudioReplay && replayQuestion) {
if (!displayAnswer || doMediaReplay && replayQuestion) {
readCardTts(SingleCardSide.FRONT)
}
if (displayAnswer) {
Expand All @@ -1480,12 +1480,12 @@ abstract class AbstractFlashcardViewer :
}

/**
* @see CardMediaPlayer.onSoundGroupCompleted
* @see CardMediaPlayer.onMediaGroupCompleted
*/
open fun onSoundGroupCompleted() {
Timber.v("onSoundGroupCompleted")
open fun onMediaGroupCompleted() {
Timber.v("onMediaGroupCompleted")
launchCatchingTask {
if (automaticAnswerShouldWaitForAudio()) {
if (automaticAnswerShouldWaitForMedia()) {
if (isDisplayingAnswer) {
automaticAnswer.scheduleAutomaticDisplayQuestion()
} else {
Expand Down Expand Up @@ -1560,7 +1560,7 @@ abstract class AbstractFlashcardViewer :
sched.buryCards(listOf(currentCard!!.id))
}
}
cardMediaPlayer.stopSounds()
cardMediaPlayer.stop()
showSnackbar(R.string.card_buried, Reviewer.ACTION_SNACKBAR_TIME)
}
return true
Expand All @@ -1574,7 +1574,7 @@ abstract class AbstractFlashcardViewer :
sched.suspendCards(listOf(currentCard!!.id))
}
}
cardMediaPlayer.stopSounds()
cardMediaPlayer.stop()
showSnackbar(TR.studyingCardSuspended(), Reviewer.ACTION_SNACKBAR_TIME)
}
return true
Expand All @@ -1591,7 +1591,7 @@ abstract class AbstractFlashcardViewer :
}
val count = changed.count
val noteSuspended = resources.getQuantityString(R.plurals.note_suspended, count, count)
cardMediaPlayer.stopSounds()
cardMediaPlayer.stop()
showSnackbar(noteSuspended, Reviewer.ACTION_SNACKBAR_TIME)
}
return true
Expand All @@ -1606,7 +1606,7 @@ abstract class AbstractFlashcardViewer :
sched.buryNotes(listOf(currentCard!!.nid))
}
}
cardMediaPlayer.stopSounds()
cardMediaPlayer.stop()
showSnackbar(TR.studyingCardsBuried(changed.count), Reviewer.ACTION_SNACKBAR_TIME)
}
return true
Expand Down Expand Up @@ -1675,7 +1675,7 @@ abstract class AbstractFlashcardViewer :
}

ViewerCommand.PLAY_MEDIA -> {
playSounds(true)
playMedia(true)
true
}

Expand Down Expand Up @@ -2222,7 +2222,7 @@ abstract class AbstractFlashcardViewer :
fun ttsInitialized() {
ttsInitialized = true
if (replayOnTtsInit) {
playSounds(true)
playMedia(true)
}
}

Expand Down Expand Up @@ -2367,7 +2367,7 @@ abstract class AbstractFlashcardViewer :
fun filterUrl(url: String): Boolean {
if (url.startsWith("playsound:")) {
launchCatchingTask {
controlSound(url)
controlMedia(url)
}
return true
}
Expand Down Expand Up @@ -2530,15 +2530,15 @@ abstract class AbstractFlashcardViewer :
* @param url
*/
@NeedsTest("14221: 'playsound' should play the sound from the start")
private suspend fun controlSound(url: String) {
private suspend fun controlMedia(url: String) {
val avTag =
when (val tag = currentCard?.let { getAvTag(it, url) }) {
is SoundOrVideoTag -> tag
is TTSTag -> tag
// not currently supported
null -> return
}
cardMediaPlayer.playOneSound(avTag)
cardMediaPlayer.playOne(avTag)
}

// Run any post-load events in javascript that rely on the window being completely loaded.
Expand Down
4 changes: 2 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ open class Reviewer :
onMark(currentCard)
}
R.id.action_replay -> {
Timber.i("Reviewer:: Replay audio button pressed (from menu)")
playSounds(true)
Timber.i("Reviewer:: Replay media button pressed (from menu)")
playMedia(doMediaReplay = true)
}
R.id.action_toggle_mic_tool_bar -> {
Timber.i("Reviewer:: Voice playback visibility set to %b", !isMicToolBarVisible)
Expand Down
Loading