6

所以我遇到了一个问题,我试图从标签创建一个网络音频源节点。代码如下所示:

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();}

问题在于最后两行。我似乎无法通过 webkit 音频上下文播放音频...

如果我做

OBJECT.play = function(){OBJECT.audio.play();}

声音将开始播放,但不会通过音频节点(这是有道理的)

我也试过

OBJECT.play = function(){OBJECT.source.noteOn(0);}
OBJECT.stop = function(){OBJECT.source.noteOff(0);}

无济于事...

非常感谢任何帮助或建议,并提前感谢您的时间!

艾萨克

编辑:当 console.logging OBJECT.source 声称有零输入和 1 输出时。这对于源节点是否正确?

4

2 回答 2

1

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/

于 2012-12-20T21:41:21.773 回答
0

Figured it out finally, but don't know exactly what the issue was...

rather then using

audio = new Audio();
audio.src = self.file;

and connecting this, I instead used

audio = document.querySelector('audio');

to select an element I had previously put into the page. I am not sure if this works simply because it gave it more time to load, or if there is something intrinsic to the API

于 2012-12-21T16:36:32.987 回答