网络音频API无法在本地使用chrome

时间:2015-04-17 17:32:51

标签: javascript html5 audio web-audio

我有一个昨天和今天运作良好的网站,我再次打开它,音频不再播放

这不会发生在Firefox上,也不会发生在我在google驱动器上托管的那个

这是调用脚本的html部分:

<script src="Scripts/frenzyMode.js"></script>
<script src="Scripts/DVR media player.js"></script>
<script src="Scripts/visualizer.js"></script>
<script src="Scripts/bodyScript.js"></script>

这里是visualizer.js:

var canvas, ctx, source, context, analyser, fbc_array, bars, bar_x, bar_width, bar_height;
    function initVisualizer() {
        context = new AudioContext();
        analyser = context.createAnalyser();
        biquad = context.createBiquadFilter();
        gainNode = context.createGain();
        canvas = document.getElementById("visualizer");
        ctx = canvas.getContext('2d');
        ctx.fillStyle = "#3f3f3f";


        analyser.smoothingTimeConstant = 0.8;
        biquad.frequency.value = 15000;
        gainNode.gain.value = 1;

        source = context.createMediaElementSource(Musique);
        source.connect(biquad);
        biquad.connect(gainNode);
        gainNode.connect(analyser);
        analyser.connect(context.destination);

        $("#frequencyNumber").html(biquad.frequency.value);
        $("#visualizerSensibilityNumber").html(analyser.smoothingTimeConstant);
        $("#gainNumber").html(gainNode.gain.value.toPrecision(3));

        framelooper()
    }

    function framelooper() {
        window.requestAnimationFrame(framelooper);
        fbcArray = new Uint8Array(analyser.frequencyBinCount);
        analyser.getByteFrequencyData(fbcArray);
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        bars = 50;
        for (i=0; i < bars; i++) {
            bar_x = i * 6;
            bar_width = 5;
            bar_height = -(fbcArray[i] / 1.75); //6 //1.75

            if (visualizerStyle == 1){
                //Simple
                ctx.fillRect(bar_x, canvas.height, bar_width, bar_height);
                $("#visualizerStyleType").html("Simple");
            }
            else if (visualizerStyle == 2) {
                //Reflection
                ctx.fillRect(bar_x, canvas.height/2, bar_width, bar_height/2);
                ctx.fillRect(bar_x, canvas.height/2, bar_width, -bar_height/2);
                $("#visualizerStyleType").html("Reflection");
            }
            else {
                //Two-faced
                ctx.fillRect(0, bar_x, -bar_height, bar_width);
                ctx.fillRect(canvas.width, bar_x, bar_height, bar_width);
                $("#visualizerStyleType").html("Face to Face");
            }
        }
    }

我完全不知道为什么会发生这种情况,因为控制台根本没有给出任何错误

1 个答案:

答案 0 :(得分:1)

我认为Chrome 42会增加对音频资源的CORS限制,这在某种程度上是以前缺失的。

可能与此重复:Web Audio API no sound playing