Disabling audio autoplay for certain fields

Hi,

I would like to add to my cards an example sentence audio that is not played automatically when the card is displayed. I would like the play button a appear and the sound to be played only if I press the button. Is it possible to do that?

Thanks in advance

5 Likes

I’m afraid this is not currently possible to control on a per-field basis - but there is a setting in the deck options to disable or enable autoplay for a given deck.

You can add this script in front template, as a result, the sound that is specified in the template first, pronunciation of a word for example, will be played. Other files will not play.

<script>

onShownHook.push(function () {

  typeans = document.getElementById("typeans");

  if (typeans) {

    typeans.blur();

  }

})

</script>

Unfortunately, it did not work. But I found another code on Reddit that worked:

<script>
  var elem = document.querySelector(".soundLink, .replaybutton"); // AnkiMobile & AnkiDroid / AnkiDesktop
  if (elem) { elem.click(); }
</script>

But the problem with this code is that, when you disable the autoplay, it still plays the first audio. Is there a solution for this? Thanks in advance.

3 Likes

Many thanks for this solution: I had been looking for a solution to playing first audio on a card. Finer control on a per-field basis would be great (one for the wishlist perhaps?)

I am not really good with codes but I have found some links that might help you:

See my post for a solution: Controlling display and function of audio buttons

1 Like

Hello!

The snippet cited by lingthusiast worked for me, however, only on desktop and not in AnkiDroid. What made it work on both platorms was

 <script>
	var elem = document.querySelector(".soundLink, .replaybutton");
	if (elem) { 
		elem.click();
	}else{
		window.onload = function(){
			var elem = document.querySelector(".soundLink, .replaybutton");
			if (elem) { elem.click();}
		}
	}
 </script> 

but then I had to disable automatic playback of audio fields for the deck in AnkiDroid.