Toggle sound by clicking on annotations

Hi there, Just managed to get a working example of the “Toggle sound by clicking on annotations” api listed here audio annotations

However, I am now stumped as how to add new additional audio clips - can anyone advise? Thanks.

They are in the html code of the snippets, that’s where you need to add them, and then get them by using usual getelementbyid as in the js part of the snippets



<audio controls id="audio1" loop=true preload width="960" height="540">
  <source src="https://sketchfab.com/blogs/community/wp-content/uploads/2021/10/sample-1.m4a" id="srcMP3" type="audio/mp3">
  <div>Your Browser will not support this audio</div>
</audio>
<audio controls id="audio2" loop=true preload width="960" height="540">
  <source src="https://sketchfab.com/blogs/community/wp-content/uploads/2021/10/sample-2.m4a" id="srcMP3" type="audio/mp3">
  <div>Your Browser will not support this audio</div>
</audio>

Hi there,

Thank you for the reply. I got the adding them to the HTML, no problem there, but in the JS, there are at least three places where the additional tracks could be added, I was wondering which lines need to be added to the JS to link them into the model. Thanks!

I’ve modified the original code example to make it easier to add audio samples: https://codepen.io/klaasnienhuis/pen/RwjYbBp

2 Likes