音量增加,直到在 Firefox 中使用 Web 音频进行剪辑



我试图使用Web Audio API进行简单的播放:

<html>
<head>
    <title>Test</title>
</head>
<body>
    <audio id="player" src="audio/song.mp3"></audio>
    <script>
    try {
        audioContext = new (window.AudioContext || window.webkitAudioContext)();
    }
    catch (e) {
        alert('Web Audio API is not supported in this browser');
    }
    var audioElement = document.getElementById("player");
    audioElement.addEventListener('canplay', function() {
        var source = audioContext.createMediaElementSource(audioElement);
        var gainNode = audioContext.createGain();
        gainNode.gain.value = 0.3;
        source.connect(gainNode);
        gainNode.connect(audioContext.destination);
        audioElement.play();
    });
    </script>
</body>
</html>

这显然在Chrome中按预期工作,但是在Firefox中却没有。在 Firefox 中发生的情况是音量逐渐增加到某个极端水平,此时开始发生剪切(wtf?如果这里没有增益节点,它只会从一开始就以可能的最大音量播放。

我很困惑为什么这样一个基本任务会导致 Firefox 出现如此荒谬的问题。由于这可能是我的系统或最新的Firefox的问题,如果有人对此进行测试,我将非常高兴。我正在使用火狐 34.0.5。

"canplay" 可以多次发射。这意味着您在 Web 音频图中多次馈送 HTMLMediaElement,并且由于 PCM 完全相关,因此会发生剪辑。iirc,Chrome有一个错误,只有第一个HTMLMediaElement通过图形输入(尽管我可能是错的(,这可以解释这一点。

最新更新