How do I autostop the first audio/media clip once the first one is playing? | XM Community
Skip to main content
Solved

How do I autostop the first audio/media clip once the first one is playing?

  • May 26, 2020
  • 1 reply
  • 8 views

I want to have three different audio clips on a page for comparison. I would like it so that if the user presses the button to play audio clip 2 while audio clip 1 is playing, audio clip one pauses or stops so that there is only one audio clip playing at a time. Is this possible?

PS: I should have API access in a day or two if that allows for this feature!

Best answer by rondev

Put this code in the JS onReady function:
jQuery("audio").bind("play",function (){
jQuery("audio").not(this).each(function (index, audio) {
audio.pause();
});
});

1 reply

rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • Answer
  • May 26, 2020

Put this code in the JS onReady function:
jQuery("audio").bind("play",function (){
jQuery("audio").not(this).each(function (index, audio) {
audio.pause();
});
});