我一直在尝试使用createMediaElementSource将音频元素连接到web音频api并让它工作但我需要做的一件事是改变音频标签的播放速率,我无法让它工作.
如果您尝试运行下面的代码,您将看到它一直有效,直到您取消注释我们设置播放速率的行.当这一行在音频中被静音.
我知道我可以使用source.playbackRate.value在AudioBufferSourceNode上设置播放速率,但这不是我想要做的,我需要在使用createMediaElementSource连接到web音频api时设置音频元素的播放速率所以我没有任何AudioBufferSourceNode.
有人设法做到了吗?
var _source,
_audio,
_context,
_gainNode;
_context = new webkitAudioContext();
function play(url) {
if (_audio) {
_audio.pause();
}
_audio = new Audio(url);
//_audio.playbackRate = 0.6;
setTimeout(function() {
if (!_gainNode) {
_gainNode = _context.createGainNode();
_gainNode.gain.value = 0.1;
_gainNode.connect(_context.destination);
}
_source = _context.createMediaElementSource(_audio);
_source.connect(_gainNode);
_audio.play();
}, 0);
}
play("http://geo-samples.beatport.com/items/volumes/volume2/items/3000000/200000/40000/9000/400/60/3249465.LOFI.mp3");
setTimeout(function () {
_audio.pause();
}, 4000);
Run Code Online (Sandbox Code Playgroud)