Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
70
rated 0 times [  77] [ 7]  / answers: 1 / hits: 33319  / 14 Years ago, wed, august 25, 2010, 12:00:00

I am new to HTML5 and I am exploring HTML5 features. There I came across audio tag.

I written code with it to play sound files.

I am having one problem with this tag. On button click, I want to change the sound file stopping the previous one.

I searched a lot but didn't find anything.
Please help me to stop the sound played by audio tag.

Here is my code;



  try
{
if(MyAudio != undefined)
{
MyAudio = null;
}
MyAudio = new Audio(filename);
MyAudio.play();
}
catch(v)
{
//alert(v.message);
}

More From » audio

 Answers
14

Try this:



  try
{
if(MyAudio != undefined)
{
MyAudio.pause();
}
MyAudio = new Audio(filename);
MyAudio.play();
}
catch(v)
{
//alert(v.message);
}

[#95813] Monday, August 23, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janjadonb

Total Points: 4
Total Questions: 114
Total Answers: 118

Location: Mali
Member since Fri, Dec 3, 2021
3 Years ago
janjadonb questions
;