There’s no way to access any kind of audio attributes like it’s metadata in card styling because Anki uses it’s own audioengine and so isn’t thing which also prohibits any direct access to the Audio
For example:
<span>
{{Vocabulary-Audio}}
</span>
<script>
var audio = document.getElementById('audio');
audio.onloadedmetadata = function() {
duration = audio.duration * 1000;
};
</script>
In this case there’s no way to ID the audio itself and duration will never be defined because the metadata can’t be loaded
Solution:
<span>
<audio id=audio>
{{Vocabulary-Audio}}
</audio>
</span>
I would greatly appreciate if we could do something like that or could have any other way to access audio attributes via code.
Thanks in advance
Keks
October 14, 2024, 7:24pm
2
I thought there used to be an explanation in the manual why this is not supported and workarounds. Now I can’t find it.
https://ankiweb.net/shared/info/683715045
For me, a convenient solution is to store the names of audio files separately in another field.
Then you could use it like this.
<audio id=audio>
<source src="{{AudioName}}" />
</audio>
An addon that can help with this.
https://ankiweb.net/shared/info/1898445115
Thanks that would work but I’d like a native implementation of that. As much as I understand the plugin till now that would exactly be what I want.
I tested it in my deck now and it doesn’t seem to work. The main promise of this plugin works like the
<audio id=audio>
<source src="{{AudioName}}" />
</audio>
works as a audio control panel if you add controls=""
but you still can’t get the attributes as hard as I tried
Keks
October 15, 2024, 11:52am
5
Keckilien:
<audio id=audio>
<audio id="audio">
<source src="{{AudioName}}" />
</audio>
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
Look at the name of the audio file and try to do what you want with it first.
<audio id="audio">
<source src="name.mp3" />
</audio>
If it works, then try the second method that I suggested.