JavaScript with Anki default media

In AnkiDroid there are currently two ways to use media in notes.

Standard Anki media:

sound:meuaudio.mp3\] \[sound:meuvideo.mp4

and HTML media:

<audio src=“meuaudio.mp3” controls></audio> <video src=“meuvideo.mp4” controls></video>

The problem is that manually using HTML media is inconvenient because:

it is very tedious; you need to write HTML in every note; and you still need to include [sound:…] anyway, otherwise media export/sync may not work correctly.

So normally we just use:

sound:file

However, I noticed that in recent versions the video behavior changed.

Even when using:

sound:meuvideo.mp4

the rendered HTML in the reviewer now becomes an HTML5 <video> element, so JavaScript works normally (playbackRate, events, controls, etc.), as if the video had been manually written as:

<video src=“meuvideo.mp4” controls></video>

But with audio this does not happen.

When using:

sound:meuaudio.mp3

the audio is still rendered as:

<a class=“soundLink” href=“playsound:q:1”>

instead of an HTML5 <audio> element.

Because of this, JavaScript cannot access native audio properties.

What is intriguing is that previously video was rendered the same way audio is rendered today, only with:

<a class=“soundLink” href=“playsound:q:1”>

So my questions are:

Why is video now rendered as HTML5 <video>? Will this HTML5 video rendering be permanent? Is there any chance the same will eventually happen for audio? Or will audio permanently continue to be rendered as: <a class=“soundLink” href=“playsound:q:1”>

This would help a lot of users who rely on JavaScript in their cards.

Consider editing your message to put sound tags and HTML tags `between backticks in code blocks. Right now some of your message is being processed by the forum as LaTeX or HTML, so some of it is unclear.

In AnkiDroid there are currently two ways to use media in notes.

Standard Anki media:

[sound:audio.mp3]
[sound:video.mp4]

and HTML media:

<audio src="audio.mp3" controls></audio>
<video src="video.mp4" controls></video>

The problem is that manually using HTML media is inconvenient because:

it is very tedious; you need to write HTML in every note; and you still need to include [sound:...] anyway, otherwise media export/sync may not work correctly.

So normally we just use:

[sound:file]

However, I noticed that in recent versions the video behavior changed.

Even when using:

[sound:video.mp4]

the rendered HTML in the reviewer now becomes an HTML5 <video> element, so JavaScript works normally (playbackRate, events, controls, etc.), as if the video had been manually written as:

<video src="video.mp4" controls></video>

But with audio this does not happen.

When using:

[sound:audio.mp3]

the audio is still rendered as:

<a class="soundLink">

instead of an HTML5 <audio> element.

Because of this, JavaScript cannot access native audio properties.

What is intriguing is that previously video was rendered the same way audio is rendered today, only with:

<a class="soundLink">

So my questions are:

Why is video now rendered as HTML5 <video>? Will this HTML5 video rendering be permanent? Is there any chance the same will eventually happen for audio? Or will audio permanently continue to be rendered as:

<a class="soundLink">

This would help a lot of users who rely on JavaScript in their cards.

Sorry, Denika. I tried to edit the post, but it’s not working anymore because it’s no longer allowed. I also tried to delete it, but that’s not allowed anymore either. So I made another post like you advised. Then I created a new post with this name: “JavaScript with Anki default media”. When you have time, please take a look.

I saw that and merged it here. I’ve also un-deleted it now.
Thanks for trying, but let’s keep this in a single thread.

Thanks again, Denika

But do you know the answer to this?

I do not – I don’t use video or JavaScript. But let’s see what the devs have to say about it.

While you’re waiting, go to Settings > About – click Copy debug info – and paste that entire result here, so they know the details of your setup.

I’m using only the standard Anki syntax:

[sound:audio.mp3]
[sound:video.mp4]

No custom media handling or special configuration.

This behavior is not specific to my device. It happens on any phone running a recent version of AnkiDroid.

I only noticed that videos are now rendered as HTML5 <video> elements, which is great for JavaScript because properties like playbackRate, events, and other native APIs work normally.

However, audio generated with

[sound:audio.mp3] 

still rendered as something like:

<a class="soundLink" href="playsound:q:1">

instead of an HTML5 <audio> element, so JavaScript cannot access the native audio properties and methods.

My question is whether this difference is intentional and meant to be long-term, and if there are any plans for audio to eventually use <audio> as well.

AnkiDroid Version = 2.23.3 (9001068fd4819c6fb66cb8239e7166868ab47859)
Backend Version = 0.1.62-anki25.09.2 (25.09.2 3890e12c9e48c028c3f12aa58cb64bd9f8895e30)
Android Version = 11 (SDK 30)
ProductFlavor = play
Device Info = samsung | samsung | a20s | a20sub | SM-A207M | qcom
Webview User Agent = Mozilla/5.0 (Linux; Android 11; SM-A207M Build/RP1A.200720.012; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/149.0.7827.163 Mobile Safari/537.36
ACRA UUID = 007663ac-11e9-4f1f-8648-521800eff6c1
FSRS = 5.1.0 (Enabled: null)
Crash Reports Enabled = true