Skip to content

Commit 6fa0c30

Browse files
committed
refactor(CardMediaPlayer): rename sound
Video is now included Use 'media', 'AvTag', or remove the 'sound' suffix Part of issue 18442
1 parent e8db1bf commit 6fa0c30

File tree

15 files changed

+253
-252
lines changed

15 files changed

+253
-252
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ abstract class AbstractFlashcardViewer :
803803
"AbstractFlashcardViewer:: OK button pressed to delete note %d",
804804
currentCard!!.nid,
805805
)
806-
launchCatchingTask { cardMediaPlayer.stopSounds() }
806+
launchCatchingTask { cardMediaPlayer.stop() }
807807
deleteNoteWithoutConfirmation()
808808
}
809809
negativeButton(R.string.dialog_cancel)
@@ -845,7 +845,7 @@ abstract class AbstractFlashcardViewer :
845845
}
846846
// Temporarily sets the answer indicator dots appearing below the toolbar
847847
previousAnswerIndicator?.displayAnswerIndicator(ease)
848-
cardMediaPlayer.stopSounds()
848+
cardMediaPlayer.stop()
849849
currentEase = ease
850850

851851
answerCardInner(ease)
@@ -1286,15 +1286,15 @@ abstract class AbstractFlashcardViewer :
12861286
}
12871287
}
12881288

1289-
private suspend fun automaticAnswerShouldWaitForAudio(): Boolean =
1289+
private suspend fun automaticAnswerShouldWaitForMedia(): Boolean =
12901290
withCol {
12911291
decks.configDictForDeckId(currentCard!!.did).waitForAudio
12921292
}
12931293

12941294
internal inner class ReadTextListener : ReadText.ReadTextListener {
12951295
override fun onDone(playedSide: CardSide?) {
12961296
Timber.d("done reading text")
1297-
this@AbstractFlashcardViewer.onSoundGroupCompleted()
1297+
this@AbstractFlashcardViewer.onMediaGroupCompleted()
12981298
}
12991299
}
13001300

@@ -1315,7 +1315,7 @@ abstract class AbstractFlashcardViewer :
13151315
val content = cardRenderContext!!.renderCard(getColUnsafe, currentCard!!, SingleCardSide.FRONT)
13161316
automaticAnswer.onDisplayQuestion()
13171317
launchCatchingTask {
1318-
if (!automaticAnswerShouldWaitForAudio()) {
1318+
if (!automaticAnswerShouldWaitForMedia()) {
13191319
automaticAnswer.scheduleAutomaticDisplayAnswer()
13201320
}
13211321
}
@@ -1361,7 +1361,7 @@ abstract class AbstractFlashcardViewer :
13611361
val answerContent = cardRenderContext!!.renderCard(getColUnsafe, currentCard!!, SingleCardSide.BACK)
13621362
automaticAnswer.onDisplayAnswer()
13631363
launchCatchingTask {
1364-
if (!automaticAnswerShouldWaitForAudio()) {
1364+
if (!automaticAnswerShouldWaitForMedia()) {
13651365
automaticAnswer.scheduleAutomaticDisplayQuestion()
13661366
}
13671367
}
@@ -1423,36 +1423,36 @@ abstract class AbstractFlashcardViewer :
14231423
Timber.d("updateCard()")
14241424
// TODO: This doesn't need to be blocking
14251425
runBlocking {
1426-
cardMediaPlayer.loadCardSounds(currentCard!!)
1426+
cardMediaPlayer.loadCardAvTags(currentCard!!)
14271427
}
14281428
cardContent = content.html
14291429
fillFlashcard()
1430-
playSounds(false) // Play sounds if appropriate
1430+
playMedia(false) // Play media if appropriate
14311431
}
14321432

14331433
/**
1434-
* Plays sounds (or TTS, if configured) for currently shown side of card.
1434+
* Plays media (or TTS, if configured) for currently shown side of card.
14351435
*
14361436
* @param doMediaReplay indicates an anki desktop-like replay call is desired, whose behavior is identical to
14371437
* pressing the keyboard shortcut R on the desktop
14381438
*/
1439-
@NeedsTest("audio is not played if opExecuted occurs when viewer is in the background")
1440-
protected open fun playSounds(doMediaReplay: Boolean) {
1439+
@NeedsTest("media is not played if opExecuted occurs when viewer is in the background")
1440+
protected open fun playMedia(doMediaReplay: Boolean) {
14411441
// this can occur due to OpChanges when the viewer is on another screen
14421442
if (!this.lifecycle.currentState.isAtLeast(RESUMED)) {
1443-
Timber.w("sounds are not played as the activity is inactive")
1443+
Timber.w("media is not played as the activity is inactive")
14441444
return
14451445
}
14461446
if (!cardMediaPlayer.config.autoplay && !doMediaReplay) return
1447-
// Use TTS if TTS preference enabled and no other sound source
1448-
val useTTS = tts.enabled && !cardMediaPlayer.hasSounds(displayAnswer)
1449-
// We need to play the sounds from the proper side of the card
1447+
// Use TTS if TTS preference enabled and no other media source
1448+
val useTTS = tts.enabled && !cardMediaPlayer.hasMedia(displayAnswer)
1449+
// We need to play the media from the proper side of the card
14501450
if (!useTTS) {
14511451
launchCatchingTask {
14521452
val side = if (displayAnswer) SingleCardSide.BACK else SingleCardSide.FRONT
14531453
when (doMediaReplay) {
1454-
true -> cardMediaPlayer.replayAllSounds(side)
1455-
false -> cardMediaPlayer.playAllSounds(side)
1454+
true -> cardMediaPlayer.replayAll(side)
1455+
false -> cardMediaPlayer.playAll(side)
14561456
}
14571457
}
14581458
return
@@ -1480,12 +1480,12 @@ abstract class AbstractFlashcardViewer :
14801480
}
14811481

14821482
/**
1483-
* @see CardMediaPlayer.onSoundGroupCompleted
1483+
* @see CardMediaPlayer.onMediaGroupCompleted
14841484
*/
1485-
open fun onSoundGroupCompleted() {
1486-
Timber.v("onSoundGroupCompleted")
1485+
open fun onMediaGroupCompleted() {
1486+
Timber.v("onMediaGroupCompleted")
14871487
launchCatchingTask {
1488-
if (automaticAnswerShouldWaitForAudio()) {
1488+
if (automaticAnswerShouldWaitForMedia()) {
14891489
if (isDisplayingAnswer) {
14901490
automaticAnswer.scheduleAutomaticDisplayQuestion()
14911491
} else {
@@ -1560,7 +1560,7 @@ abstract class AbstractFlashcardViewer :
15601560
sched.buryCards(listOf(currentCard!!.id))
15611561
}
15621562
}
1563-
cardMediaPlayer.stopSounds()
1563+
cardMediaPlayer.stop()
15641564
showSnackbar(R.string.card_buried, Reviewer.ACTION_SNACKBAR_TIME)
15651565
}
15661566
return true
@@ -1574,7 +1574,7 @@ abstract class AbstractFlashcardViewer :
15741574
sched.suspendCards(listOf(currentCard!!.id))
15751575
}
15761576
}
1577-
cardMediaPlayer.stopSounds()
1577+
cardMediaPlayer.stop()
15781578
showSnackbar(TR.studyingCardSuspended(), Reviewer.ACTION_SNACKBAR_TIME)
15791579
}
15801580
return true
@@ -1591,7 +1591,7 @@ abstract class AbstractFlashcardViewer :
15911591
}
15921592
val count = changed.count
15931593
val noteSuspended = resources.getQuantityString(R.plurals.note_suspended, count, count)
1594-
cardMediaPlayer.stopSounds()
1594+
cardMediaPlayer.stop()
15951595
showSnackbar(noteSuspended, Reviewer.ACTION_SNACKBAR_TIME)
15961596
}
15971597
return true
@@ -1606,7 +1606,7 @@ abstract class AbstractFlashcardViewer :
16061606
sched.buryNotes(listOf(currentCard!!.nid))
16071607
}
16081608
}
1609-
cardMediaPlayer.stopSounds()
1609+
cardMediaPlayer.stop()
16101610
showSnackbar(TR.studyingCardsBuried(changed.count), Reviewer.ACTION_SNACKBAR_TIME)
16111611
}
16121612
return true
@@ -1675,7 +1675,7 @@ abstract class AbstractFlashcardViewer :
16751675
}
16761676

16771677
ViewerCommand.PLAY_MEDIA -> {
1678-
playSounds(true)
1678+
playMedia(true)
16791679
true
16801680
}
16811681

@@ -2222,7 +2222,7 @@ abstract class AbstractFlashcardViewer :
22222222
fun ttsInitialized() {
22232223
ttsInitialized = true
22242224
if (replayOnTtsInit) {
2225-
playSounds(true)
2225+
playMedia(true)
22262226
}
22272227
}
22282228

@@ -2367,7 +2367,7 @@ abstract class AbstractFlashcardViewer :
23672367
fun filterUrl(url: String): Boolean {
23682368
if (url.startsWith("playsound:")) {
23692369
launchCatchingTask {
2370-
controlSound(url)
2370+
controlMedia(url)
23712371
}
23722372
return true
23732373
}
@@ -2530,15 +2530,15 @@ abstract class AbstractFlashcardViewer :
25302530
* @param url
25312531
*/
25322532
@NeedsTest("14221: 'playsound' should play the sound from the start")
2533-
private suspend fun controlSound(url: String) {
2533+
private suspend fun controlMedia(url: String) {
25342534
val avTag =
25352535
when (val tag = currentCard?.let { getAvTag(it, url) }) {
25362536
is SoundOrVideoTag -> tag
25372537
is TTSTag -> tag
25382538
// not currently supported
25392539
null -> return
25402540
}
2541-
cardMediaPlayer.playOneSound(avTag)
2541+
cardMediaPlayer.playOne(avTag)
25422542
}
25432543

25442544
// Run any post-load events in javascript that rely on the window being completely loaded.

AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ open class Reviewer :
434434
}
435435
R.id.action_replay -> {
436436
Timber.i("Reviewer:: Replay media button pressed (from menu)")
437-
playSounds(doMediaReplay = true)
437+
playMedia(doMediaReplay = true)
438438
}
439439
R.id.action_toggle_mic_tool_bar -> {
440440
Timber.i("Reviewer:: Voice playback visibility set to %b", !isMicToolBarVisible)

0 commit comments

Comments
 (0)