Video and audio should only play together, at the same time

Why is it that when a video file (MP4) is playing and I tap to play an audio file (MP3), the video that was playing before does not stop? Both play at the same time. Why does this happen?

The way videos are handled has changed. Now, when a video file (MP4) is playing and you press “play” on an audio file (MP3), the previously playing video does not stop. Both play simultaneously, which is a problem because my notes contain both audio and video.

The same thing happens when one video (MP4) is playing and you press play on another video (MP4): the first one does not stop, and both videos play at the same time. Please fix this.

However, this does not happen with audio files (MP3 + MP3). That is, if one audio file is playing and you press “play” on another audio file, the first one stops. They do not play at the same time. Why does this work correctly for audio + audio, but not for video + video or audio + video?

It should work the same way for videos as it does for audio. Will you fix this permanently? That is, once it is fixed, will it stay that way and not change again in a future update?

Duplicate post - Reddit - The heart of the internet .

I see that you were directed over here, but you didn’t respond to abdnh’s question/comment there. At least it’s now clear you’re asking about Android – but we still need to know how you’ve attached the video and audio to your note and how you’re using it in your card templates.

What version of AnkiDroid are you seeing this on? Go to Settings > About – click “Copy debug info” – paste that entire result here when you respond.

2 Likes

Hi, good morning! Yes, I asked this question on Reddit and a guy said that this doesn’t happen in Anki on the computer. He also asked me how my audio files are set up in Anki, but I didn’t really understand what he meant by that. I tried to reply, but for some reason my comment isn’t showing up publicly.

So I’ll reply here to you instead.

I use AnkiDroid. I’m on the latest version of AnkiDroid. I add audio and video files to Anki normally — I download them and then put them into Anki. I don’t use any code, and I don’t use any special settings that could be causing this.

The guy there said that this doesn’t happen on the computer, which means this is an AnkiDroid issue. The developers either forgot about it or didn’t notice this part.

I also tested it on AnkiWeb, but it behaves like AnkiDroid — actually, it’s worse. Even the audio doesn’t work properly. That is, if one audio is playing and I press play on another audio, the one that was playing before doesn’t stop. Both audios play at the same time.

Here is how my videos and audios are set up normally.

Here’s what you’ve shown: you create a deck of one card and share it with us. I don’t understand how you play video… and mp4 is supposed to be fine, since I don’t even have a button in Ankiuser. A lot of audio plays, and that’s how it works by default on pages. But when you’re in control, there needs to be some kind of player to bypass it… and that’s code, and you certainly shouldn’t be making it. Here’s my recent code… and the deck is already in the shared library https://ankiweb.net/shared/info/115901085 … I created a special player there and stopped previous files myself, but the default one can only be stopped by clicking a button… and browsers are prohibited from launching anything until the user clicks on the page. So they removed all the flashy pages, but the automation suffered. But after the first click, I was able to get the audio to even autoplay in Ankiuser using code. So there are workarounds, but whether or when they will be made is still a question, but if you design a good deck yourself, everything can be solved.

No, you didn’t understand what I asked.

If you allow me, I’ll explain again in a more detailed way:

about a bug in AnkiDroid. It’s about how audio and video are played.

Why is it that when a video file (mp4) is playing and you tap to play an audio file (mp3), the video that was playing before does not stop, and both play at the same time?

To explain it better: when a video file (mp4) is playing and you press “play” on an audio file (mp3), the video that was already playing does not stop. Both play at the same time, which is a problem because my notes contain both audio and video.

The same thing happens if a video (mp4) is playing and you press play on another video (mp4). The first one does not stop, and both videos play at the same time. Please fix this.

However, this does not happen with audio and audio (mp3 and mp3). That is, if one audio file is playing and you press “play” on another audio file, the first one stops; they do not play at the same time.

Why does this work correctly for audio + audio, but not for video + video or audio + video? It should work the same way for both videos and audios.

Are you going to fix this in a way that will be permanent? I mean, if it gets fixed, will it stay fixed and not change again after an update?

Notes:

I use AnkiDroid and I’m on the latest version. I add normal audio and video files to Anki (I download them and put them into Anki). I don’t use any code or special settings that could be causing this.

I asked this question on Reddit, and someone said that this does not happen in Anki for desktop. That is, if a video is playing and you play an audio file, the video stops. They don’t play at the same time. This suggests that it might be a bug in AnkiDroid. It seems like this part was overlooked.

I also tested it on AnkiWeb, and it behaves like AnkiDroid — actually, it’s worse. Even audio doesn’t work correctly there. That is, if one audio is playing and you press play on another audio, the first one does not stop. Both play at the same time.

I’m talking about audio/video and video/video, which do not stop when one is already playing and I press play on another. Both play at the same time.

Audio/audio works correctly: if one audio is playing and I press play on another, the first one stops. They do not play together.

I downloaded your deck, in which you configured the template to “stop things.” I think it was supposed to work for the problem I’m having, but it didn’t. In fact, I didn’t even understand it very well. Your deck doesn’t even have videos, only audios. And if the goal of your configuration was to stop audio when another one plays using JavaScript, I don’t understand why that’s necessary. AnkiDroid already does this by itself. As I said, audio/audio works fine. The problem is audio/video and video/video.

Maybe you did this because you didn’t understand how my videos are made in AnkiDroid. Or maybe it was meant to work on AnkiWeb, since on AnkiWeb even audio/audio doesn’t work.

So I’m attaching here a small deck from my Anki with only 5 notes, just so you can see how it is. How things work(https://ankiweb.net/shared/info/915691254)

When you open the note, the video starts playing. Then you press some of the audios and you’ll see that the video does not stop. Both play at the same time. And I didn’t change anything—there’s no configuration at all. Everything is just normal audios and videos.

Now… I didn’t understand your configuration. Actually, I don’t understand anything about code. (I asked ChatGPT to explain it a bit.) But it looks like you have normal audios that you created manually and that exist in your phone’s storage, and also audios created via JavaScript, through code you put in the template. Is that the kind of audio you’re talking about? (Like the guy on Reddit.) But as I said, my audios and videos are normal, manually made—that is, I download them from the internet and put them into Anki. I don’t even know how to do it any other way, and I don’t even know what that other way is.

Now… I didn’t understand your configuration. Actually, I don’t understand anything about code. (I asked ChatGPT to explain it a bit.) But it looks like you have normal audios that you created manually and that exist in your phone’s storage, and also audios created via JavaScript, through code you put in the template. Is that the kind of audio you’re talking about? (Like the guy on Reddit.) But as I said, my audios and videos are normal, manually made—that is, I download them from the internet and put them into Anki. I don’t even know how to do it any other way, and I don’t even know what that other way is.

But… what about you? Did you create those codes because you think they might solve the audio/video problem, right? But from what I researched, this JavaScript approach is not reliable. It takes a huge amount of work to make it, and when Anki updates, it may stop working. I know that a JavaScript code can sometimes be fixed to work again if something like that happens. But it may also never work again, because Anki might block that specific type of function—for example, preventing a video from being stopped when an audio plays, even with JavaScript.

For example, in your deck it looks like you reduced the audio speed using JavaScript. But one day, after an update, that might no longer be possible, because Anki blocked that kind of thing even with JavaScript.

Anyway… you are an AnkiDroid developer—can you report this problem to the team? Because this only happens in AnkiDroid and AnkiWeb. In the desktop Anki, it doesn’t happen. So the problem is in AnkiDroid. Maybe the developers forgot or didn’t notice this part. Can you fix it? And when it’s fixed and Anki updates, could it all break again and stop working?

If that’s the case, could audio/audio also stop working properly in the future? That is, if one audio is playing and I press play on another, it might not stop anymore either, becoming like audio/video?

And about these JavaScript codes: can they really block the function of stopping a video when an audio plays, even with JavaScript? Can they also block things like reducing playback speed, like in your example?

But… what about you? Did you create those codes because you think they might solve the audio/video problem, right?

I don’t make videos. I only use audio. And there have always been problems with the web version, as there’s no answer input field there. I can’t solve these issues; I’m not the developer of all these systems, but I can solve them for myself through deck design.

But it may also never work again, because Anki might block that specific type of function—for example, preventing a video from being stopped when an audio plays, even with JavaScript.

I agree. Something might be blocking it. But you’re mainly talking about AnkiDroid’s error, and they follow Anki. If, as you said, everything’s fine in Anki but not in AnkiDroid, then that’s great, but I need to check. I checked, and my video doesn’t stop either.

For example, in your deck it looks like you reduced the audio speed using JavaScript. But one day, after an update, that might no longer be possible, because Anki blocked that kind of thing even with JavaScript.

This is unlikely, since AnkiDroid follows Anki’s development, and Anki should also offer full support for displaying any code allowed in a browser with security restrictions. Whether or not to pause is ultimately a user preference. Even if you want the video to pause, it’s not always ideal, as some people might want the video to continue without sound and play it as a screensaver… say, there’s a sea of ​​water and you’re just listening to the lyrics. All sorts of ideas are possible, but what’s useful and how it will work isn’t my decision.

Anyway… you are an AnkiDroid developer—can you report this problem to the team? Because this only happens in AnkiDroid and AnkiWeb. In the desktop Anki, it doesn’t happen. So the problem is in AnkiDroid. Maybe the developers forgot or didn’t notice this part. Can you fix it? And when it’s fixed and Anki updates, could it all break again and stop working?

I’m not an AnkiDroid developer, and even if I were, not everything is so easily resolved. There are project managers, technical constraints, even a community of people. Even if thousands of people scream that something shouldn’t be like this, management might listen and implement it… or they might not. Anything can happen.
But I already said that AnkiDroid follows Anki’s behavior, and if this behavior isn’t considered a mistake in Anki, they are obligated to replicate it in AnkiDroid.
Almost anyone can report a bug in AnkiDroid, but you have to be registered on GitHub, of course.
I’ll report this bug there, and we’ll see when they implement it.

Here’s what he reported: There is no pause in video when pressing the play button of another media file · Issue #19962 · ankidroid/Anki-Android · GitHub

And about these JavaScript codes: can they really block the function of stopping a video when an audio plays, even with JavaScript? Can they also block things like reducing playback speed, like in your example?

We don’t have JavaScript access to the player; even getting the file name is a problem. But the way I’ve set it up is standard audio (and possibly video) that can be placed on an HTML page, and they can’t prohibit that. I can play standard audio at different speeds, but I don’t know what they’ll do with their player. I was planning on creating an add-on that would at least quickly retrieve the audio file name, and once that was in place, I could write custom code to enable playback.
Playing one audio file in the background at low volume, and the lyrics in a different stream at a different volume, isn’t that bad. Although it’s better for the Anki player to play them in order, and it would be nice if you could pause the sound by pressing it again… if it’s a long one, that makes sense, but apparently only short sounds were intended, and they don’t see the point yet.

Ok, thanks for replying.

So there are two types of files that can be used in Anki?

Standard HTML audio using , and Anki’s audio player using [sound:…]?

But I didn’t fully understand the JavaScript part. What I asked you was this:

What if I create a JavaScript code that pauses a video when an audio starts playing, and then Anki updates and it stops working? Could we fix the code so it works again?

Or even if we fix the code, could it still stop working because Anki might have removed that specific behavior — “not pausing the video anymore when an audio plays” — even when using JavaScript?

Can Anki do that? Remove that functionality even when using JavaScript?

I didn’t understand your answer very well. You said yes?

But then I asked you the same thing about audio playback speed reduction that you use in your deck, which uses JavaScript, and you said no — that even if Anki updated, it wouldn’t be able to prevent it, that there would be no way to remove that functionality.

So does this idea of “Anki not being able to remove it” only apply to audio speed reduction, and not to videos?

Or does it have to do with the fact that you made your audio a standard HTML element?

If audio works with JavaScript because it is a standard HTML element, does the same apply to video?

If I embed a video using a standard HTML element instead of Anki’s [sound:…] player, will JavaScript be able to control it reliably (pause, change speed, etc.)?

Or is video still handled differently by Anki even when embedded as HTML?

So, combining both ideas: if instead of using Anki’s [sound:…] player, I embed audio and video using standard HTML elements ( and ) inside the card template, will JavaScript be able to control them reliably (for example, pause a video when audio starts playing, or change playback speed)?

And if that’s the case, is using standard HTML always safe?

That is, even if Anki updates, will it never be able to remove that functionality or prevent reducing audio speed as long as it’s a standard HTML element?

Likewise, if I use a standard HTML element, even if Anki updates, will it never be able to prevent pausing a video when an audio starts playing?

If tha

t’s true, could you create one JavaScript code that pauses a video when an audio starts playing, and another one to reduce playback speed?

Note:

I only use front and back fields.

Debug info

AnkiDroid Version = 2.23.1 (3f3133b496b531383e9a6494f5a7704634935308)

Backend Version = 0.1.62-anki25.09.2 (25.09.2 3890e12c9e48c028c3f12aa58cb64bd9f8895e30)

Android Version = 14 (SDK 34)

ProductFlavor = play

Device Info = motorola | motorola | lamulg | lamulg_g | moto e15 | mt6768

Webview User Agent = Mozilla/5.0 (Linux; Android 14; moto e15 Build/UUTBS34.40-36-1; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/143.0.7499.34 Mobile Safari/537.36

ACRA UUID = bee27cca-8f31-4be7-880b-30207f9ca9dc

FSRS = 5.1.0 (Enabled: false)

Crash Reports Enabled = true

You ask a lot of questions, so it’s easy to get lost in them. By asking one question at a time, someone might give a short answer, but long conversations might not be of much interest to the forum.

So there are two types of files that can be used in Anki?

Why two types? Are you talking about video and audio? Usually, yes, mp4 for video, but mp3 is still preferable for audio.
If you’re talking about the "<audio> and <video>" tags, there are two of them, and they’re made manageable in the same way using JavaScript.
I haven’t tested the video. But I did embed a YouTube video, since Anki is essentially an HTML page, so a lot is possible.
I even made an add-on that can create a crossword puzzle:
There’s a link to the deck on the page https://ankiweb.net/shared/info/451577856, but it’s no longer valid. You can check it out here: https://ankiweb.net/shared/info/1254999438

Anki has its own player (Method 1), and you have to paste “[sound:…]” into the field when you copy the data. But getting the name of the pasted file isn’t so easy, and it’s necessary to launch it later, like I do with "<audio>" (Method 2, but that’s not the file type). You’ll have to copy the name from the field yourself and paste it into another special field. Of course, you could create an add-on that always adds the file name hidden on the page… I’ve thought about it, maybe I will. Then, having the name of the file being played will make everything easier. But the good news is that on ankiweb.net, they already represent all their playing sounds as "<audio>", and with a script, you can hack into the controls and get the file name.
You might ask, why not do away with “[sound:…]” altogether and just write the name of the desired audio or video file? Because Anki syncs using these fields, it simply won’t see your entries. You’ll have to manually transfer them to a media folder on your computer or smartphone, and the web won’t even have these files. So there are complications, and it’s not all that simple.

What if I create a JavaScript code that pauses a video when an audio starts playing, and then Anki updates and it stops working? Could we fix the code so it works again?

If they don’t drastically modify the HTML page, which they most likely won’t, then everything will work as is.
Many people are still using older versions, believing that either the add-ons are more convenient or something else has changed, but they’re more accustomed to it.

Can Anki do that? Remove that functionality even when using JavaScript?

It’s hard for them to do that; they have other things to do, and they’re not responsible for the script or any issues it might cause. They’re just creating the standard functionality so it works. They shouldn’t touch any additional features. Of course, they could implement a feature that completely disables sound, but the system can do that for you, too. :slight_smile:

If I embed a video using a standard HTML element instead of Anki’s [sound:…] player, will JavaScript be able to control it reliably (pause, change speed, etc.)?

Perhaps, as you can see, even when inserting a YouTube frame, complete control is exercised over code that isn’t even stored in Anki, but is taken remotely from there.

So, combining both ideas: if instead of using Anki’s [sound:…] player, I embed audio and video using standard HTML elements ( and ) inside the card template, will JavaScript be able to control them reliably (for example, pause a video when audio starts playing, or change playback speed)?

It’s good to use Anki apps, but when we do this in the browser, the browser itself, for security reasons, requires the user to click somewhere, meaning permission to play the sound. So, you can do this with a button, but with autoplay, you can’t do it that easily. So, for me, the first time I show a side of the map, it’s silent, but once it’s started playing, they reload part of the page content, and the sound is always on.
Again, I’ll say it’s not perfect. Anki was created a long time ago, while HTML5 audio and video standards were introduced in 2008-2010.

And if that’s the case, is using standard HTML always safe?

I don’t understand the question, since HTML itself is simple formatting, essentially bolding and italics, but JavaScript, especially if we’re pulling in third-party libraries, can sometimes produce suspicious results. But you open it in your browser, so how do you live then?

If that’s true, could you create one JavaScript code that pauses a video when an audio starts playing, and another one to reduce playback speed?

I already described how they have their own player, and I can’t control it from JavaScript. I can control my files. I left the [sound:…] field because it’s required for file synchronization and to play sounds when a deck is opened, according to the deck’s settings. If you want your own playback, you’ll usually disable it in the settings.

So, in my example deck, there’s audio with their [sound:…] fields, and there’s my audio with a link to the same file as [sound:…], and I can control it and change the speed. If I play my audio and then their field, you’ll see that my audio stops, since their code has been reversed and I control it. Stopping Anki is harder, though, although I’ve tried simply launching an empty file without sound and it stopped, but I removed that from the deck… but I thought about that.

If you’d rather study only in Anki and not in Ankidroid, you can install various plugins. There’s a good plugin for slowing down audio; I use it: https://ankiweb.net/shared/info/312734862
I was planning on making an audio plugin myself, but it’s not that fast. I have a lot of problems with other code, and, of course, everyone else has a lot of problems with everything.
Here’s a hint: I need a special plugin for Ankidroid that would add functionality even to Ankidroid: I have long audio files, like lectures, or simply want to memorize a poem. I need to listen to a section of the audio, return to the beginning of that section, and listen again, possibly multiple times, but then move on to the next section and memorize it again. Basically, it’s a small player with a special feature for students.

So, we’re waiting for them to fix the Ankidroid code for you, as this is the simplest solution and should be implemented and fixed.

I don’t quite understand what you need, because I need to fully describe the entire learning process and what exactly is so great about it, when you have both audio and video on the same card. Why aren’t they separated into separate cards? So, there would be one recording, but the video field would show on one card, and the audio on another. I don’t know everything, of course, but maybe that’s exactly what you need.

1 Like

Thanks for the replies, @kaiu!!!

I’ve been pretty explicit to the OP over various communications channels over the past couple of weeks that they’re not going to get a response to a barrage of questions, especially when mixed with criticism. I feel you’re saying the same thing again here:

You ask a lot of questions, so it’s easy to get lost in them. By asking one question at a time, someone might give a short answer, but long conversations might not be of much interest to the forum.

The current communication style isn’t workable at all. It’s well-intentioned, but results in borderline harassment. I wouldn’t want to subject the team or myself to this whilst working on the bug, and want to strongly discourage this style of communication in future.

If there’s a bug, we need a reasonable summary of the issue (and the reason the feature is wanted), ideally with an apkg, and version numbers where Anki Desktop and AnkiDroid differ.

4 Likes

Ok, I understand. There are two ways to play audio/video in Anki:

Anki Player ([sound:…])

→ Anki controls it

→ JavaScript does NOT work, it CANNOT control it.

Standard HTML (<audio> / <video>)

→ Anki does not control it

→ JavaScript DOES control it, it will always work

But then, if using the Anki Player ([sound:…]) is not a good idea, because Anki is the one in control, JavaScript never works and cannot control it;And so the best option really is to use standard HTML (<audio> / <video>), because Anki does not control it; JavaScript does. So how did they manage to remove the “autoplay” function even when using standard HTML (<audio> / <video>)?

Therefore, it is not a good idea to use JavaScript even with standard HTML (<audio> / <video>), because when Anki updates, it may stop working. They might even remove these two functions — stopping the video when the audio plays and reducing the playback speed — even when using standard HTML (<audio> / <video>), just like they removed the autoplay function.

We have to accept that this is really a bug that can no longer be ignored. It has to be fixed. You reported this bug on GitHub, so they will fix it in the next app update. Let’s wait for them to correct it. I thank everyone for their attention.

The browser doesn’t have this feature either. It was banned because the audio ads on every page were annoying. Anki follows browser standards, or rather, they use everything that’s already there. A user must press a button for the sound to play. In their app, they receive a list of audio files in their player and control it, leaving everything else to the browser and not preventing you from clicking there or doing anything else.

So it comes down to the same thing!. I understand that autoplay is blocked at the browser/WebView level rather than by Anki itself.

However, this does not imply that other standard HTML functionalities—such as (<audio> / <video>), for example automatically pausing a video when another audio starts or changing playback speed—can be removed in the same manner.

Moreover, using standard HTML (<audio> / <video>) its bad

It forces us to do everything twice: we have to use Anki’s player ([sound:…]) for syncing with AnkiWeb, and standard HTML (<audio> / <video>) to use JavaScript.

That means double the work, and for people who create many notes, this becomes tiring.

So it comes down to the same thing!. I understand that autoplay is blocked at the browser/WebView level rather than by Anki itself.

However, this does not imply that other standard HTML functionalities—such as (<audio> / <video>), for example automatically pausing a video when another audio starts or changing playback speed—can be removed in the same manner.

Moreover, using standard HTML (<audio> / <video>) its bad

It forces us to do everything twice: we have to use Anki’s player ([sound:…]) for syncing with AnkiWeb, and standard HTML (<audio> / <video>) to use JavaScript.

That means double the work, and for people who create many notes, this becomes tiring.

But now, changing the subject a bit: in the GitHub issue you created ( There is no pause in video when pressing the play button of another media file · Issue #19962 · ankidroid/Anki-Android · GitHub ) to report this bug, there are several people commenting. Two of them said they can fix it. They seem to be Anki developers (ujjol1234 and ShaanNarendran).

However, they asked: “Could you please assign it to me?” I’m not entirely sure what that means, but it seems they need this for something. And it looks like only the person who created the GitHub issue—who in this case is you—can do that. Could you assign it to them?

Also, it seems they didn’t fully understand that this issue also happens with video/video, and that on AnkiWeb it’s even worse—it even happens with audio/audio. Because of that, their proposed solution might not actually fix the bug.

Anyone can approach someone with a problem, but not everyone understands it, much less manages the development process.
They can take on everything at once and propose options, and then the manager can look at everything and choose the best solution.
It’s the team’s decision. So they agree on what they’ll do and how, and if everyone agrees, they’ll assign someone to do it.
I can describe my vision, but it’s better for them to write it themselves; they’ll better understand what they can do based on the existing code.
Let’s not interfere; we’ll always have time to shit :slight_smile: