Anki 2.1.33 Linux audio stops working

Hello,

Audio will stop working randomly (maybe after 5 cards or after 80). I’m using mpv to play audio. When it breaks, I can see mpv is still open in the process list. It was working in 2.1.22
All it happens is audio doesn’t play anymore, only way to restore it is restarting Anki.

Anki is 2.1.33 downloaded from the Anki website.

mpv version:
mpv 0.32.0 Copyright © 2000-2020 mpv/MPlayer/mplayer2 projects
built on UNKNOWN
ffmpeg library versions:
libavutil 56.31.100 (runtime 56.51.100)
libavcodec 58.54.100 (runtime 58.91.100)
libavformat 58.29.100 (runtime 58.45.100)
libswscale 5.5.100 (runtime 5.7.100)
libavfilter 7.57.100 (runtime 7.85.100)
libswresample 3.5.100 (runtime 3.7.100)
ffmpeg version: n4.3.1

This is quite a surprise. I guess, running Tools - Check Media doesn’t report any missing or unused files.

The following steps to create mpv log file might not help but I’m not sure what else to do to find where is the problem or how to reproduce it.

  • Install “Debug No Sound” - https://ankiweb.net/shared/info/881480056

    The add-on will prevent Anki from restarting mpv if mpv is no longer responding and mpv log file won’t be overwritten.

  • Don’t restart Anki

  • Open the Debug Console, copy-paste the following lines and press Ctrl+Return to tell mpv to create mpv.debug.log.txt in the Anki2 folder.

    https://docs.ankiweb.net/#/misc?id=debug-console

    import os
    from aqt import mw
    from aqt.sound import mpvManager
    logfile = os.path.join(mw.pm.base, 'mpv.debug.log.txt')
    path = os.path.expanduser(logfile)
    with open(os.path.join(mw.pm.base, 'mpv.conf'), 'a') as f:
        f.write('log-file={}\n'.format(path))
    print('log-file:', mpvManager.get_property('log-file'))
    # restart mpv to apply new settings
    mpvManager.shutdown()
    print('log-file:', mpvManager.get_property('log-file'))
    

    As an alternative, manually create mpv.conf in the Anki2 folder with log-file=....

  • Then restart Anki and review cards until there’s no sound.

Once there’s no sound, click the audio replay button a few times, then look at the ‘mpv.debug.log.txt’ in Anki2 folder. Maybe it’ll show why there’s no sound or maybe not.

https://docs.ankiweb.net/#/files?id=file-locations

And maybe open the Debug Console in Anki and run this code.

from aqt.sound import av_player, mpvManager
print(av_player.current_player)
mpvManager.shutdown()
print(mpvManager.get_property("mpv-version"))
print(av_player.current_player)
2 Likes

Hi, thanks for the response.

When I did the first part of the instructions, this was the result:

import os
... from aqt import mw
... from aqt.sound import mpvManager
... logfile = os.path.join(mw.pm.base, 'mpv.debug.log.txt')
... path = os.path.expanduser(logfile)
... with open(os.path.join(mw.pm.base, 'mpv.conf'), 'a') as f:
...     f.write('log-file={}\n'.format(path))
... print('log-file:', mpvManager.get_property('log-file'))
... # restart mpv to apply new settings
... mpvManager.shutdown()
... print('log-file:', mpvManager.get_property('log-file'))
mpv timed out, restarting
Exception: unable to put request
log-file: None
mpv timed out, restarting
Exception: unable to put request
log-file: None

However, I checked and the log file was created and mpv was using it, so it may not be relevant.

After I used Anki for a while, I encountered this bug. This is the last part of the log file:

[1286.121][v][cplayer] starting audio playback
[1286.121][v][cplayer] playback restart complete @ 0.000000
[1286.122][d][cplayer] Run command: change-list, flags=64, args=["shared-script-properties", "append", "osc-margins=0.000000,0.000000,0.000000,0.000000"]
[1286.122][v][cplayer] Set property: shared-script-properties -> 1
[1286.122][d][cplayer] Run command: enable-section, flags=64, args=["showhide", "allow-hide-cursor+allow-vo-dragging"]
[1286.122][d][cplayer] Run command: enable-section, flags=64, args=["showhide_wc", "allow-hide-cursor+allow-vo-dragging"]
[1286.153][d][osc] osc_init
[1286.153][d][cplayer] Run command: change-list, flags=64, args=["shared-script-properties", "append", "osc-margins=0.000000,0.000000,0.000000,0.000000"]
[1286.153][v][cplayer] Set property: shared-script-properties -> 1
[1287.045][v][af] filter input EOF
[1287.045][v][af] filter output EOF
[1287.045][v][cplayer] audio EOF reached
[1287.045][v][cplayer] EOF code: 1
[1287.045][d][ad] Uninit decoder.
[1287.046][d][cplayer] Terminating demuxers...
[1287.046][d][cplayer] Done terminating demuxers.
[1287.046][v][cplayer] finished playback, success (reason 0)
[1287.046][i][cplayer]
[1287.046][v][ao/pulse] draining...
[1287.227][d][cplayer] Run command: loadfile, flags=64, args=["/home/paravalancha/.local/share/Anki2/User 1/collection.media/968a3d56684dbd6778b8455dcacb259d.mp3", "append-play", ""]
[1287.227][d][osc] osc_init
[1287.228][d][cplayer] Run command: stop, flags=64, args=[]
[1287.234][d][cplayer] Run command: change-list, flags=64, args=["shared-script-properties", "append", "osc-margins=0.000000,0.000000,0.000000,0.000000"]
[1287.235][v][cplayer] Set property: shared-script-properties -> 1
[1287.266][d][cplayer] Run command: disable-section, flags=64, args=["showhide"]
[1287.267][d][cplayer] Run command: disable-section, flags=64, args=["showhide_wc"]
[1298.108][d][cplayer] Run command: stop, flags=64, args=[]
[1303.688][d][cplayer] Run command: stop, flags=64, args=[]
[1338.768][d][cplayer] Run command: stop, flags=64, args=[]
[1339.959][d][cplayer] Run command: stop, flags=64, args=[]
[1341.729][d][cplayer] Run command: stop, flags=64, args=[]
[1342.529][d][cplayer] Run command: stop, flags=64, args=[]
[1343.869][d][cplayer] Run command: stop, flags=64, args=[]
[1344.099][d][cplayer] Run command: stop, flags=64, args=[]
[1344.300][d][cplayer] Run command: stop, flags=64, args=[]
[1344.559][d][cplayer] Run command: stop, flags=64, args=[]
[1344.929][d][cplayer] Run command: stop, flags=64, args=[]
[1345.359][d][cplayer] Run command: stop, flags=64, args=[]

Those “Run command” entries are when I tried repeatedly to play audio. If you want, I could upload the whole log file.

I also tested version 2.1.26 and I didn’t encounter this bug.

This is all very strange.

If possible, try to update to the latest mpv version - https://mpv.io/installation/
For example, on Ubuntu it can be installed by adding PPA: https://launchpad.net/~mc3man/+archive/ubuntu/mpv-tests

Then start Anki from the terminal. I’m not sure, but I think, once there’s no sound, the last line in the terminal will be “mpv timed out, restarting”.
Then try to find mpv in the list of running processes. Since you have “Debug no sound” add-on installed and if I didn’t make any mistake and as far as I understand the code, you shouldn’t be able to find mpv in the list of running processes.
Then click the audio play button a few times and upload somewhere ‘mpv.debug.log.txt’, maybe on https://gofile.io
Then open the Debug Console and run this code. Let me know what is the output.

from aqt.sound import av_player, mpvManager
print('----------------------')
print('av_player:', av_player.current_player)
print('version:', mpvManager.get_property("mpv-version"))
print('pid:', mpvManager._proc.pid)
print('av_player:', av_player.current_player)
print('----------------------')
print('Shutdown')
print('----------------------')
print('is_running:', mpvManager.is_running())
mpvManager.shutdown()
print('is_running:', mpvManager.is_running())
print('----------------------')
print('Restart')
print('----------------------')
print('av_player:', av_player.current_player)
print('version:', mpvManager.get_property("mpv-version"))
print('pid:', mpvManager._proc.pid)
print('av_player:', av_player.current_player)

Actually, after a bit of thinking, it’d be better to skip all these steps for now and just restart Anki, wait for no sound, click the audio play button a few times and upload mpv.debug.log.txt somewhere.

Installed mpv version is the latest release, 0.32.0.
Here is the link to the log file: https://gofile.io/d/bc3Aoi
When audio stops playing, I can see in the process list that mpv is still running. I ran Anki from the terminal and I didn’t get any message when the bug happened.

Edit: after using 2.1.26 some more, I also encountered the bug there. So the latest version I’m confident that didn’t have it is 2.1.22.

@auntanki to help to figure out if it’s the same problem or not, please try the following.

  • Install “Debug No Sound” - https://ankiweb.net/shared/info/881480056

  • Don’t restart Anki

  • Open the Debug Console, copy-paste the following lines and press Ctrl+Return to tell mpv to create mpv.debug.log.txt in the Anki2 folder.

    https://docs.ankiweb.net/#/misc?id=debug-console

    import os
    from aqt import mw
    from aqt.sound import mpvManager
    logfile = os.path.join(mw.pm.base, 'mpv.debug.log.txt')
    path = os.path.expanduser(logfile)
    with open(os.path.join(mw.pm.base, 'mpv.conf'), 'a') as f:
        f.write('log-file={}\n'.format(path))
    print('log-file:', mpvManager.get_property('log-file'))
    # restart mpv to apply new settings
    mpvManager.shutdown()
    print('log-file:', mpvManager.get_property('log-file'))
    
  • Then restart Anki and review cards until there’s no sound.

Once there’s no sound, click the audio replay button a few times, then find ‘mpv.debug.log.txt’ in the Anki2 folder and upload it somewhere, e.g. https://gofile.io

Then open the Debug Console in Anki, copy-paste this code and press Ctrl+Return.

from aqt.sound import av_player, mpvManager
print("av_player.current_player:", av_player.current_player)
print("_on_done:", mpvManager._on_done)
print("is_idle:", mpvManager.get_property("idle-active"))
av_player.current_player = None
print("av_player.current_player:", av_player.current_player)

Let me know what is the output and try to review a few cards. Maybe the audio will work again.

@paravalancha thank you!

Yes, mpv 0.32.0 is the latest stable version, but I thought it might be worth to try to install the latest git version from the unofficial app repository. But it seems that though the latest build is newer than 0.32 it’s still quite outdated, at least on Ubuntu 20.04 (“mpv git-2020-04-17-a09c769”), and installing it or maybe compiling the latest git version might make no difference and won’t resolve the problem.

I couldn’t reproduce the issue, but it seems to be clear what’s wrong now. It looks like the audio starts playing, Anki sends a “stop” command, but for some reason mpv doesn’t tell Anki that the file has ended and a new audio file can be played safely.

The correct log file should looks something like this

[2162.901][d][cplayer] Run command: loadfile, flags=64, args=[url=“/home/nickolay/.local/share/Anki2/movies2anki/collection.media/DanielleFeinberg_2015P_0.00.18.355-0.00.20.873.mp3”, flags=“append-play”, options=“”]
[2162.901][i][cplayer] Playing: /home/nickolay/.local/share/Anki2/movies2anki/collection.media/DanielleFeinberg_2015P_0.00.18.355-0.00.20.873.mp3
[2162.901][v][cplayer] Running hook: ytdl_hook/on_load
[2162.902][v][ytdl_hook] ytdl:// hook
[2162.902][v][ytdl_hook] not a ytdl:// url
[2162.902][d][cplayer] Run command: stop, flags=64, args=[flags=“”]
[2162.902][v][cplayer] finished playback, success (reason 2)
[2162.902][i][cplayer]
[2162.904][d][cplayer] Run command: loadfile, flags=64, args=[url=“/home/nickolay/.local/share/Anki2/addons21/814349176/awesometts/.cache/google-0fdceeb1-97e59cff-bb1d8ebf-08bc229e-de2e4f64.mp3”, flags=“append-play”, options=“”]

but your log file looks like

[ 489.670][d][cplayer] Run command: loadfile, flags=64, args=[“/home/paravalancha/.local/share/Anki2/User 1/collection.media/9b219835204d80e799b75f6aea5ea7b4.mp3”, “append-play”, “”]
[ 489.670][d][osc] osc_init
[ 489.670][d][cplayer] Run command: change-list, flags=64, args=[“shared-script-properties”, “append”, “osc-margins=0.000000,0.000000,0.000000,0.000000”]
[ 489.670][v][cplayer] Set property: shared-script-properties → 1
[ 489.671][d][cplayer] Run command: stop, flags=64, args=
[ 489.701][d][cplayer] Run command: disable-section, flags=64, args=[“showhide”]
[ 489.701][d][cplayer] Run command: disable-section, flags=64, args=[“showhide_wc”]
[ 510.265][d][cplayer] Run command: stop, flags=64, args=
[ 766.305][d][cplayer] Run command: stop, flags=64, args=
[ 769.226][d][cplayer] Run command: stop, flags=64, args=

and strangely there’re no “finished playback, success (reason 2)”.

Maybe increasing the log file level will provide some additional information, but I don’t know how to do it, my recent experiments on Windows were not successful and I need to try to do it on Ubuntu, or maybe it won’t be necessary.

I think, the “Debug No Sound” add-on can be deleted now.

For now, please install this add-on with a possible fix and let me know how it goes. It reverts back to Anki 2.1.26 or Anki 2.1.22 behaviour and probably won’t work since there’s no sound with Anki 2.1.26 but won’t hurt to try.

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

1 Like

Hello,

First I used 2.1.33 normally except this time with verbose mpv logging (msg-level=all=trace in mpv.conf). Here is the log: https://gofile.io/d/xJYqtl
There’s a lot more output but I didn’t notice anything strange before the bug happened.

Then I tried adding load-scripts=no to mpv.conf, since I thought perhaps the mpv instance launched by Anki was loading some of my custom scripts and this was causing a conflict. However, I encountered the bug after a short while.

Finally I tried the “No Sound Fix 1” add-on, and it worked! Or at least I was able to study more than 160 cards without encountering the bug. I will report back if it happens again with that add-on enabled. Thanks!

1 Like

Thank you. It seems to be the same issue. Please install No Sound Fix 1 for now too - https://ankiweb.net/shared/info/1088053614

@kelciour You probably have a better feel for this at this point than I do - do you think we should we start considering a change in the next Anki update?

1 Like

@dae yes, I have no explanations why the current code is not working on a few occasions and couldn’t reproduce the issue, but considering there were no reports of something similar happening before Anki 2.1.28, I have no reasons not to went ahead and revert it back as it used to be prior to Anki 2.1.28.

If the issue will be still present, maybe something like this will be enough to make it disappear.

     def stop(self) -> None:
-        self.command("stop")
+        if self.get_property("idle-active") and self._on_done:
+            self._on_done()
+        else:
+            self.command("stop")

idle-active
Return yes if no file is loaded, but the player is staying around because of the --idle option.
mpv.io

It might introduce a slight delay, maybe from 1 to 100 ms, but it shouldn’t be noticeable since Anki will only call “stop” to interrupt the current playback and most of the time “stop” won’t be called and there will be no delay.

1 Like

@kelciour Wow, this looks and smells specific to the way media is played on Linux, but the user experience appears quite parallel to what is discussed on this other thread: Unable to play longer audio on cards

fwiw

The add-on should still work. Give it a try. It the issue will be still present, I’ll try a different approach and upload No Sound Fix 2.