# Audio playing problem

**URL:** <https://forums.ankiweb.net/t/audio-playing-problem/1974>\
**Category:** Help\
**Created:** [August 7, 2020, 1:19am UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974 "2020-08-07T01:19:02Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![congbosun](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@congbosun](https://forums.ankiweb.net/u/congbosun)\
**Post date:** [August 7, 2020, 1:19am UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/1 "2020-08-07T01:19:02Z")

</div>

Hi, I’m using Anki 2.1.29 on macOS 10.14.6.  
The audio can’t be played after several cards studied.  
(Since I updated Anki)  
I need to reopen Anki to recover it.  
Thank you for developing Anki 🙂

---

<div class="post-metadata">

**Author:** ![dae](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/dae/32/65_2.png) [@dae](https://forums.ankiweb.net/u/dae)\
**Post date:** [August 7, 2020, 3:31am UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/2 "2020-08-07T03:31:13Z")

</div>

I presume you’re using the standard Anki version, not the one for older machines?

@kelciour is the resident mpv expert, and may have a suggestion

---

<div class="post-metadata">

**Author:** ![congbosun](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@congbosun](https://forums.ankiweb.net/u/congbosun)\
**Post date:** [August 7, 2020, 3:47am UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/3 "2020-08-07T03:47:34Z")

</div>

Yes, I downloaded it from top page this week, and I’m using 2017 macbook pro

---

<div class="post-metadata">

**Author:** ![kelciour](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/kelciour/32/14770_2.png) [@kelciour](https://forums.ankiweb.net/u/kelciour)\
**Post date:** [August 7, 2020, 3:33pm UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/4 "2020-08-07T15:33:31Z")

</div>

Thanks @dae

@congbosun I’m just an average mpv user for the most part who just uses mpv as a default video and audio player and happened to know a bit of coding. There were a number of changes to mpv in Anki 2.1.29 that I’m responsible for, but they were supposed to improve and add support for Windows and not break anything.

Once you start Anki, try to open the Debug Console ([https://docs.ankiweb.net/#/misc?id=debug-console](https://docs.ankiweb.net/#/misc?id=debug-console)), copy-paste the following code and press Cmd+Return. Then close the Debug Console window and review your cards as usual. Once the audio can’t be played, please wait about 5 seconds and try to click the audio play button a few times. Then close Anki and upload somewhere `mpv.log.txt` from your Desktop, e.g. on [https://gofile.io](https://gofile.io).

```python
from aqt import mw
from aqt.sound import av_player, MpvManager, OnDoneCallback, SoundOrVideoPlayer
from anki.sound import AV_REF_RE, AVTag, SoundOrVideoTag
from aqt.mpv import MPV, MPVBase, MPVCommandError

# assert isinstance(av_player.players[0], MpvManager)

class MpvManager(MPV, SoundOrVideoPlayer):

    from anki.utils import isLin

    if not isLin:
        from aqt.mpv import MPVBase
        default_argv = MPVBase.default_argv + [
            "--input-media-keys=no",
        ]

    def __init__ (self, base_path: str) -> None:
        from aqt.sound import _packagedCmd
        mpvPath, self.popenEnv = _packagedCmd(["mpv"])
        self.executable = mpvPath[0]
        self._on_done: Optional[OnDoneCallback] = None
        self.default_argv += ["--config-dir=" + base_path]
        super(). __init__ (window_id=None, debug=False)

    def play(self, tag: AVTag, on_done: OnDoneCallback) -> None:
        assert isinstance(tag, SoundOrVideoTag)
        self._on_done = on_done
        path = os.path.join(os.getcwd(), tag.filename)
        self.command("loadfile", path, "append-play")
        self.set_property("term-status-msg", "loadfile {}".format(path))
        gui_hooks.av_player_did_begin_playing(self, tag)

    def stop(self) -> None:
        self.set_property("term-status-msg", "stop {}".format(self._on_done))
        self.command("stop")

    def toggle_pause(self) -> None:
        self.set_property("term-status-msg", "set pause {}".format(not self.get_property("pause")))
        self.set_property("pause", not self.get_property("pause"))

    def seek_relative(self, secs: int) -> None:
        self.command("seek", secs, "relative")

    def on_end_file(self) -> None:
        self.set_property("term-status-msg", "on_end_file {}".format(self._on_done))
        if self._on_done:
            self._on_done()

    def shutdown(self) -> None:
        self.close()

    # Legacy, not used
    ##################################################

    togglePause = toggle_pause
    seekRelative = seek_relative

import aqt.sound

aqt.sound.mpvManager.shutdown()
aqt.sound.mpvManager = MpvManager(mw.pm.base)
path = os.path.expanduser("~/Desktop/mpv.log.txt")
aqt.sound.mpvManager.set_property("log-file", path)
av_player.players[0] = aqt.sound.mpvManager

print(path)
print('Done!')

```

The code contains a couple of additional log messages that maybe will help to narrow the issue down and eventually fix it.

---

<div class="post-metadata">

**Author:** ![congbosun](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@congbosun](https://forums.ankiweb.net/u/congbosun)\
**Post date:** [August 12, 2020, 2:26pm UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/5 "2020-08-12T14:26:36Z")

</div>

Hi,  
Here is the file.  
Hope it helps:)  
[https://gofile.io/d/8iTajQ](https://gofile.io/d/8iTajQ)

2020年8月8日(土) 0:43 Nickolay Nonard via Anki Forums \<[anki2@discoursemail.com](mailto:anki2@discoursemail.com)\>:

---

<div class="post-metadata">

**Author:** ![kelciour](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/kelciour/32/14770_2.png) [@kelciour](https://forums.ankiweb.net/u/kelciour)\
**Post date:** [August 12, 2020, 3:51pm UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/6 "2020-08-12T15:51:57Z")

</div>

I’m not sure where’s the problem. At least, nothing seems to be wrong with Anki. At the same time, before Anki was closed, mpv seems to play `何月.mp3` several times just fine too.

At first, try to update mpv to the latest version.

1. Close Anki.

2. Download mpv-0.32.0.tar.gz from [https://laboratory.stolendata.net/~djinn/mpv\_osx/](https://laboratory.stolendata.net/~djinn/mpv_osx/) and unpack it somewhere.

3. Right-click on `mpv.app` and select “Show Package Contents”. Then go to `mpv.app/Contents/MacOS`.

4. Find Anki in the Applications folder.

5. Right-click on `Anki.app` and select “Show Package Contents”. Then go to `Anki.app/Contents/Resources/audio`.

6. Remove `mpv` and `lib` from the folder, i.e. from `Anki.app/Contents/Resources/audio`, and replace it with `mpv` and `lib` from `mpv.app`.

7. Then restart Anki, open the Debug Console, copy-paste the following lines and press Command+Return. This is just to make sure that mpv version is 0.32.

---

<div class="post-metadata">

**Author:** ![congbosun](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@congbosun](https://forums.ankiweb.net/u/congbosun)\
**Post date:** [August 14, 2020, 1:28pm UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/7 "2020-08-14T13:28:45Z")

</div>

Hi, I don’t know if the solution resolves the issue or not,  
but version 0.32 is VERY VERY convenient!!  
Thank you

2020年8月13日(木) 1:01 Nickolay Nonard via Anki Forums \<[anki2@discoursemail.com](mailto:anki2@discoursemail.com)\>:

---

<div class="post-metadata">

**Author:** ![congbosun](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@congbosun](https://forums.ankiweb.net/u/congbosun)\
**Post date:** [August 17, 2020, 6:51am UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/8 "2020-08-17T06:51:58Z")

</div>

Hi, the problem happened again  
(With MPV 0.32)

2020年8月14日(金) 22:28 孫琮博 \<[congbosun@gmail.com](mailto:congbosun@gmail.com)\>:

---

<div class="post-metadata">

**Author:** ![congbosun](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@congbosun](https://forums.ankiweb.net/u/congbosun)\
**Post date:** [August 17, 2020, 6:55am UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/9 "2020-08-17T06:55:41Z")

</div>

After I ran the code you told me when the problem happened, it got an error:

```auto

mpv timed out, restarting

Traceback (most recent call last):

File "aqt/mpv.py", line 350, in _get_response

File "queue.py", line 178, in get

_queue.Empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "aqt/mpv.py", line 377, in _send_request

File "aqt/mpv.py", line 354, in _get_response

aqt.mpv.MPVTimeoutError: unable to get response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "aqt/mpv.py", line 350, in _get_response

File "queue.py", line 178, in get

_queue.Empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "aqt/main.py", line 1493, in onDebugRet

File "<string>", line 129, in <module>

File "aqt/mpv.py", line 616, in set_property

File "aqt/mpv.py", line 606, in command

File "aqt/mpv.py", line 384, in _send_request

File "aqt/mpv.py", line 377, in _send_request

File "aqt/mpv.py", line 354, in _get_response

aqt.mpv.MPVTimeoutError: unable to get response

```

2020年8月17日(月) 15:51 孫琮博 \<[congbosun@gmail.com](mailto:congbosun@gmail.com)\>:

---

<div class="post-metadata">

**Author:** ![kelciour](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/kelciour/32/14770_2.png) [@kelciour](https://forums.ankiweb.net/u/kelciour)\
**Post date:** [August 17, 2020, 8:06pm UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/10 "2020-08-17T20:06:05Z")

</div>

I’m not sure how it could have happened and how to reproduce it.

Since it seems to be some random crashes and can’t be narrowed down to the specific file, I’d suggest, to run this code in the Debug Console just one time to tell mpv to create its log file in `~/Library/Logs/mpv.anki.txt`, and keep reviewing as usual.

```
import os

from aqt import mw
from aqt.sound import mpvManager

path = os.path.expanduser("~/Library/Logs/mpv.anki.txt")
with open(os.path.join(mw.pm.base, 'mpv.conf'), 'a') as f:
    f.write('log-file={}\n'.format(path))
mpvManager.shutdown()
print('log-file:', mpvManager.get_property('log-file'))

```

Or maybe this is not necessary and mpv already creates its log file in `~/Library/Logs/mpv.log`.

> A special case is the macOS bundle, it will create a log file at ~/Library/Logs/mpv.log by default.

> **[mpv.io](https://mpv.io/manual/master/#options-log-file)**
>
> a free, open source, and cross-platform media player

When the audio stops working again, maybe in a day or a week, go to `~/Library/Logs` and look at the last lines or upload `~/Library/Logs/mpv.anki.txt` somewhere. Maybe it’ll contain some information what had happened. Maybe mpv just crashed while playing the audio file.

But do not close Anki. Instead, open the Debug Console, run this code and click the audio play button or review a few cards with audio. Maybe the audio will work again.

```
from aqt.sound import mpvManager
if mpvManager._on_done:
   mpvManager._on_done()

```

If it won’t work, try this code instead and click the audio play button.

```
from aqt.sound import av_player
av_player.current_player = None

```

---

<div class="post-metadata">

**Author:** ![congbosun](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@congbosun](https://forums.ankiweb.net/u/congbosun)\
**Post date:** [August 19, 2020, 2:47am UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/11 "2020-08-19T02:47:27Z")

</div>

Thank you for the suggestion!  
I’ll give it a try.

2020年8月18日(火) 5:16 Nickolay Nonard via Anki Forums \<[anki2@discoursemail.com](mailto:anki2@discoursemail.com)\>:

---

<div class="post-metadata">

**Author:** ![congbosun](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@congbosun](https://forums.ankiweb.net/u/congbosun)\
**Post date:** [August 20, 2020, 2:47am UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/12 "2020-08-20T02:47:27Z")

</div>

Hi,  
The problem happened again, and I uploaded the log file:  
[https://gofile.io/d/MHBFuV](https://gofile.io/d/MHBFuV)

The `_on_done()` method works and the lines before I ran the method are:

```auto
[0.145][d][cplayer] Run command: stop, flags=64, args=[]
[0.146][v][osd/libass] Shaper: FriBidi 1.0.8 (SIMPLE) HarfBuzz-ng 2.6.4 (COMPLEX)
[0.146][v][osd/libass] Setting up fonts...
[0.147][v][osd/libass] Using font provider coretext
[0.147][v][osd/libass] Done.
[0.147][d][cplayer] Run command: enable-section, flags=64, args=["input_osc", "allow-hide-cursor+allow-vo-dragging"]
[0.147][d][cplayer] Run command: define-section, flags=64, args=["input_forced_osc", "", "force"]
[0.147][d][cplayer] Run command: enable-section, flags=64, args=["input_forced_osc", "allow-hide-cursor+allow-vo-dragging"]
[0.180][d][cplayer] Run command: disable-section, flags=64, args=["showhide"]
[0.180][d][cplayer] Run command: disable-section, flags=64, args=["showhide_wc"]
[0.808][d][cplayer] Run command: stop, flags=64, args=[]
[1.716][d][cplayer] Run command: stop, flags=64, args=[]
[2.185][d][cplayer] Run command: stop, flags=64, args=[]
[2.621][d][cplayer] Run command: stop, flags=64, args=[]
[2.897][d][cplayer] Run command: stop, flags=64, args=[]
[3.443][d][cplayer] Run command: stop, flags=64, args=[]
[4.169][d][cplayer] Run command: stop, flags=64, args=[]
[4.452][d][cplayer] Run command: stop, flags=64, args=[]
[4.697][d][cplayer] Run command: stop, flags=64, args=[]
[6.260][d][cplayer] Run command: stop, flags=64, args=[]
[8.722][d][cplayer] Run command: stop, flags=64, args=[]
[10.226][d][cplayer] Run command: stop, flags=64, args=[]
[11.081][d][cplayer] Run command: stop, flags=64, args=[]
[11.801][d][cplayer] Run command: stop, flags=64, args=[]
[12.242][d][cplayer] Run command: stop, flags=64, args=[]
[14.064][d][cplayer] Run command: stop, flags=64, args=[]
[76.151][d][cplayer] Run command: stop, flags=64, args=[]
[78.360][d][cplayer] Run command: stop, flags=64, args=[]
[90.203][d][cplayer] Run command: stop, flags=64, args=[]

```

2020年8月18日(火) 5:16 Nickolay Nonard via Anki Forums \<[anki2@discoursemail.com](mailto:anki2@discoursemail.com)\>:

---

<div class="post-metadata">

**Author:** ![kelciour](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/kelciour/32/14770_2.png) [@kelciour](https://forums.ankiweb.net/u/kelciour)\
**Post date:** [August 20, 2020, 8:53pm UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/13 "2020-08-20T20:53:08Z")

</div>

Thank you. This is much better. For now, one last time, I guess, please install [https://ankiweb.net/shared/info/881480056](https://ankiweb.net/shared/info/881480056), ignore the description since you’ve already told mpv where to save the log file, restart Anki.and review cards as usual.

Once it happens again, upload the log file again. This time Anki won’t restart mpv and the log file won’t be overwritten. Maybe the last lines will contain some useful info or maybe not.

---

<div class="post-metadata">

**Author:** ![congbosun](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@congbosun](https://forums.ankiweb.net/u/congbosun)\
**Post date:** [September 13, 2020, 2:24am UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/14 "2020-09-13T02:24:23Z")

</div>

Hi, I’m using Anki 2.1.33 and MPV 0.32  
Now I can’t play audio even after restarting Anki.  
The log is here (I accidentally overwrote the old one though)

`https://gofile.io/d/CSRhYa`

---

<div class="post-metadata">

**Author:** ![congbosun](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@congbosun](https://forums.ankiweb.net/u/congbosun)\
**Post date:** [September 13, 2020, 2:29am UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/15 "2020-09-13T02:29:38Z")

</div>

And maybe you can tell me how to debug.  
I’m a software engineer and familiar with Python.

---

<div class="post-metadata">

**Author:** ![kelciour](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/kelciour/32/14770_2.png) [@kelciour](https://forums.ankiweb.net/u/kelciour)\
**Post date:** [September 13, 2020, 12:04pm UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/16 "2020-09-13T12:04:28Z")

</div>

The log file looks good to me. According to it, just one file was played.

This is really strange. If it’s something related to Anki, restarting Anki should help all the time. Since there were no error messages after restarting Anki, it should mean that Anki was able to communicate with mpv just fine.

I’d try to,

- Install Debug No Sound again if it was removed - [https://ankiweb.net/shared/info/881480056](https://ankiweb.net/shared/info/881480056) - to prevent Anki from restarting mpv and keep the log file as it is.

- Once there’s no sound, click the audio replay button a few times, wait a few seconds seconds and look at the ‘mpv.debug.log.txt’ by opening it again in the text editor. The last `loadfile` command should contain the audio filename that was clicked.

If the log file had been changed on disk, Sublime Text will reload it automatically or ask to refresh the editor. It’s probably true for all popular text editors but I’m not sure and it might be safe to just open the log file again.

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

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

```

Since no audio is playing, “current\_player” should be None and “is\_idle” should be True.

Maybe it’ll be different this time.

If current\_player is not None and set to mpvManager, but is\_idle is True, it means that mpv didn’t tell Anki that the current audio file is no longer being played, Anki never called \_on\_done callback to set current\_player to None and Anki’s still thinking that mpv is busy playing the audio file. If this is the case, clicking the audio play button a few times should result in a number of “stop” commands in the log file.

If current\_player is None and is\_idle is True, but there’s no sound if you click the audio play button, I’d check the log file just to make sure that it’s being played by mpv.

If you know the audio filename in the collection.media folder, you could try to play it directly with mpv using the Debug Console in Anki.

```auto
from aqt.sound import mpvManager
filename = "youdao-49a9b3ef-7c0423c9-9fd3286e-3457bfca-1f91443c.mp3"
path = os.path.join(os.getcwd(), filename)
mpvManager.command("loadfile", path)

```

If there’s no sound, maybe locate mpv in Applications/Anki.app and try to play the audio file or maybe from the terminal app with `/Applications/Anki.app/Contents/Resources/audio/mpv`.

Maybe it’ll help to locate where is the problem.

tl;dr: if there’s no sound, click the audio play button a few times, run the code in the debug console to take a look at av\_player.current\_player and is\_idle values and check the log file.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [May 1, 2023, 5:31am UTC](https://forums.ankiweb.net/t/audio-playing-problem/1974/17 "2023-05-01T05:31:34Z")

</div>

Closed on May 1, 2023, 5:31am UTC


