So I am having a problem where I am trying to create a web-audio source node from a tag. The Code Looks Like this:
OBJECT.musicContext= new webkitAudioContext();
OBJECT.audio = new Audio();
OBJECT.audio.src = self.file;
OBJECT.source = OBJECT.musicContext.createMediaElementSource(OBJECT.audio);
var analyser= OBJECT.musicContext.createAnalyser();
analyser.fftSize=1024;
OBJECT.analyser=analyser
OBJECT.gain = self.musicContext.createGain();
OBJECT.gain.gain.value = .01
OBJECT.source.connect(OBJECT.gain)
OBJECT.gain.connect(OBJECT.analyser)
OBJECT.analyser.connect(OBJECT.musicContext.destination)
OBJECT.play = function(){OBJECT.source.play();}
OBJECT.stop = function(){OBJECT.source.stop();}
The problem is with the last two lines. I can't seem to get the audio to play through the webkit audio context...
If I do
OBJECT.play = function(){OBJECT.audio.play();}
the sound will start playing, but not through the audio node (which makes sense)
I have also tried
OBJECT.play = function(){OBJECT.source.noteOn(0);}
OBJECT.stop = function(){OBJECT.source.noteOff(0);}
to no avail...
Any help or suggestions are greatly Appreciated, and thanks in advance for your time!
Isaac
EDIT: when console.logging OBJECT.source is claims that there are zero inputs and 1 output. Is this correct for a source node?
The AudioDestinationNode interface represents the end destination of an audio graph in a given context — usually the speakers of your device. It can also be the node that will "record" the audio data when used with an OfflineAudioContext .
You should try your page in Chrome as Safari currently doesn't send the correct data to the Analyzer Node. If you're using an Audio()
object with the Web Audio API then you should be able to control the playback with it instead of using .noteOn()/.noteOff()
.
Here's the test case: http://screamingrobots.com/misc/safariaudiobug/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With