AnalyserNode
与MediaStream
的{{1}}完美配合。但我无法让Chrome分析getUserMedia
来自MediaStream
的{{1}}。调用RTCPeerConnection.onaddstream
会创建一个零数组:
.getByteFrequencyData
将pc.onaddstream = function(evt) {
var conn = _conns[user];
conn.audio = $('<audio>', {
src: URL.createObjectURL(evt.stream),
autoplay: true
});
conn.context = Microphone.context();
conn.sourceNode = conn.context.createMediaStreamSource(evt.stream);
conn.analyserNode = conn.context.createAnalyser();
conn.sourceNode.connect(conn.analyserNode);
conn.analyserInterval = setInterval(function() {
var bufferLength = conn.analyserNode.frequencyBinCount;
var dataArray = new Uint8Array(bufferLength);
conn.analyserNode.getByteFrequencyData(dataArray);
console.log(dataArray);
}, 50);
};
的参数替换为createMediaStreamSource
,这是我从Microphone.stream()
获得的流,用数据填充数组。
我在Linux上使用Chrome 47。