[bug report] HTML AudioElement tag cannot replay 3 times

Problem description:
I import an audio external media file through the HTML AudioElement tag in a deck and play it in the following way (repeat 3 times during each playback)

  const handler = {
    playAudio: function() {
      const audio = document.getElementById('a-audio') as HTMLAudioElement;
      audio.currentTime = 0;
      audio.playCount = 3;
      audio.play();
    }
  };

  onMounted(() => {
    func.i();

      // replay three times
      const audio = document.getElementById('a-audio') as HTMLAudioElement;
      audio.addEventListener('ended', () => {
        console.log(audio.playCount);
        audio.playCount--;
        if (audio.playCount > 0) {
          audio.play();
        }
      });

      // 播放
      handler.playAudio();
  });

But it doesn’t work on ankimobile. (This deck can be played normally on both Windows and Android)

Question: How can I find the cause of the problem’s error? So that I can solve it.
I want to see the information on the console,
but I found that the iOS client does not support it. Is there any other way.

I hope to get some help, thank you :blush:

The only officially-supported way to play audio is with [sound:…] tags. I’m afraid when you start using JavaScript, you become responsible for dealing with any issues that come up.

https://docs.ankiweb.net/templates/styling.html#javascript

For debugging, you can either inject messages into the DOM, or try something like GitHub - liriliri/eruda: Console for mobile browsers

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.