evosaurus
evosaurus

Reputation: 31

Web Audio API. Play sound on click of button

I am a complete novice with HTML5 and coding for that matter. I have been trying to get to grips with the web audio API. I want a sound to play at a click of a button. I used a tutorial posted on HTML5Rocks, but cannot get it to work. I have tried to use jfiddle to help me troubleshoot, but to no avail.

here is my code: http://jsfiddle.net/ue8WP/

Upvotes: 3

Views: 1464

Answers (2)

user2039789
user2039789

Reputation: 97

Try this:

function playsound()
{    
    var filepath='sounds/'+....+'.mp3'; //example
    var audio = new Audio();   
    audio.src = filepath;
    audio.controls = true;
    audio.autoplay = true;

}

Upvotes: 1

krivinarius
krivinarius

Reputation: 118

Here's a simplified version of your code that should work fine. You only need to load some other sample sound, since there is a problem with fetching the one you provided (not allowed by Access-Control-Allow-Origin).

http://jsfiddle.net/WB6Pw/3/

Upvotes: 0

Related Questions