[Linux] Bug report - audio not playing for subsequent cards after missing audio

This only happens on Linux and not on Windows.

If I have a card with one missing audio file, or it can’t access the audio file for whatever reason (i.e. audio is an online link and there is no Internet) then MPV just completely gives up and no subsequent audio files on any subsequent cards will ever play. Killing MPV using the equivalent of Task Manager used to fix it. But now the only fix is to restart Anki.

This caused frustration while I was traveling today offline and every one of my cards had one field that used internet-based audio - it broke every audio (even files I downloaded) and obviously restarting the program was not feasible.

I cannot seem to reproduce on debian linux (sid, but not up to date). Maybe your mpv binary is the issue? mpv --version shows this for me:

mpv 0.39.0 Copyright © 2000-2024 mpv/MPlayer/mplayer2 projects
libplacebo version: v7.349.0
FFmpeg version: 7.1.1-1+b1
FFmpeg library versions:
   libavcodec      61.19.100 (runtime 61.19.101)
   libavdevice     61.3.100
   libavfilter     10.4.100
   libavformat     61.7.100
   libavutil       59.39.100
   libswresample   5.3.100
   libswscale      8.3.100

Edit: You could try to reproduce by uninstalling mpv and installing mplayer instead. That should rule out issues with mpv.

I can’t reproduce it either, Windows and Linux.

Maybe you’re using some old Anki version. Since Anki 25.02.6, playback of remote audio URLs via mpv has been disabled due to CVE-2025-62187. Instead, Anki will try to play the filename (the last part of the url) from the collection.media folder (if it exists).

https://github.com/ankitects/anki/releases/tag/25.02.6

  • Specially-crafted sound file references could cause files to be written to arbitrary locations on Windows & Linux.

  • References to audio files outside of the media folder are no longer allowed.

Maybe try updating to the latest Anki version (25.09.2) and use the Localize Media add-on to download remote audio files or use Find and Replace to replace [sound:https://upload.wikimedia.org/wikipedia/commons/0/0c/En-us-audio.ogg] with <audio src="https://upload.wikimedia.org/wikipedia/commons/0/0c/En-us-audio.ogg" controls></audio> (or edit the underlying HTML using the </> button at the right side of the field) to be able to play remote audio links in the latest Anki version.

To play the <audio> tag automatically, the following code could be added to the front or back template, but if some card also includes one or more [sound:...] tags, the audio will be played at the same time.

<script>
document.querySelector("audio")?.play().catch(() => {});
</script>
1 Like

mpv –version reveals I have an earlier version of both mpv and FFmpeg but the most recent version of Anki.

I tried sudo apt update and then sudo apt install mpv, neither of those changed anything (it still thinks the old version I’m running is the newest). Does that mean I have to update my kernel? (I manually downgraded to an older one because I was having freezing issues)

edit: updating the Kernel does not unlock the new version. I am running Linux Mint 22.2

No, the kernel has nothing to do with it. You can only download a more recent version of mpv if the repositories of your distro ship newer versions. So if you want a newer mpv version, then you have to upgrade the entire OS. It doesn’t seem like there is a newer Linux Mint version available, though, which means the mpv version you currently have is the one you’re stuck with for now. This isn’t neccessarily a bad thing though; there is value in fixed release models (I use debian for that very reason).

Anyways, you can try this next:

Also try this if you haven’t already:

If only online files are affected, you might want to try downloading the files to solve your issue. I never used that addon, but this seems logical if you want to do it in batch:


(I wouldn’t recommend the other option posted by @kelciour where <audio> tags are used; mostly because it makes playing multiple audio files in succession more difficult to set up and it interferes with Ankis “unused file” detection)

Maybe try to create a log file.

  1. Run the following code in the debug console.

    https://docs.ankiweb.net/misc.html#debug-console

    import os
    from aqt.sound import mpvManager
    path = os.path.expanduser("~/Desktop/mpv.log.txt")
    mpvManager.set_property("log-file", path)
    print(mpvManager.get_property("log-file"))
    
  2. Click the replay button and wait a few seconds.

  3. Open the log file in any text editor and take a look at the last few lines that should look something like this.

    [3269.419][d][cplayer] Run command: loadfile, flags=64, args=[url="C:\\Users\\...\\AppData\\Roaming\\Anki2\\User 1\\collection.media\\audio.mp3", flags="replace", options="pause=no"]
    ...
    [3269.463][v][cplayer] starting audio playback
    ...
    [3279.762][v][cplayer] finished playback, success (reason 0)
    

Maybe the output will contain some useful information why there’s no sound.

It should be fine. Though the <audio> tag is not officially supported, the audio file will still be detected as “used” by Check Media and should be included in the exported apkg file as well.

I tried your code and it didn’t output anything in that folder (neither before nor after MPV breaks). Maybe there is a way to have it output directly in the console that appears?

Not sure if this is of any use - this started happening after I downloaded this conversion addon which switched my MP3’s to OPUS and JPG’s to AVIF.

https://ankiweb.net/shared/info/1151815987

Some of my media files are referenced on multiple cards and if one of those cards was not in the batch selection that I converted, the references would not change, causing a “missing media“ error to appear and all audio playback to stop. I have manually corrected the references on a lot of these cards, but the issue still persists sometimes.

Did you only paste the code into the dev console or also run it?

Anyways, have you tried this:

Pasted the code. Ran it multiple times.

It’s probably easier to just switch to mplayer. I followed the top comment on this post:

I think it works.

Travelling again today (return trip from my original post)

All audio broke again even after switching to mplayer.

The problem is not with the Anki app itself but rather the addon that fetches Google TTS audio for the given field on the card. So maybe I should take it up with the addon developer.

However, this particular addon is linked on the official Anki documentation for Text to Speech voice creation…

Field Replacements - Anki Manual

1 Like

The add-on linked is for demonstration purposes. I recommend HyperTTS.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.