Reputation: 11
I have a web audio project the needs to take an existing tag on a page, grab it and play it through my web audio audio context.
<audio id="music" controls="true">
<source src="DW2-AU01.mp3" type="audio/mp3" />
</audio>
Perhaps I'm making a mistake here, but loading the file into a buffer like this works:
var source = myAudioContext.createBufferSource();
source.buffer = myBuffers['FFA01.mp3'];
source.connect(myAudioContext.destination);
source.noteOn(0);
However, if I set it up with an tag on the page and try to play the sound like this:
var source = myAudioContext.createMediaElementSource($('#music'));
source.connect(myAudioContext.destination);
source.noteOn(0);
I get INVALID_STATE_ERR: DOM Exception 11. I feel like I've exhausted my google searches, and the html5rocks examples that everyone posts has him creating the tag in jQuery, not using one that already exists on the page.
Is this possible? Any help is appreciated!
Upvotes: 1
Views: 1819
Reputation: 3724
You are passing a jQuery reference. What if you try sending a reference to the native audio element?
var source = myAudioContext.createMediaElementSource($('#music')[0]);
Upvotes: 3