为什么这个html5音频不能在chrome上工作,但在safari上工作得很好



我想在我的网络上播放一些声音,这是我的代码,它适用于safari,但cat不适用于chrome。任何人都可以给我一个解决方案

$(button).click(function() {
        $.ajax({
            url : "messageaction",
            type : "post",
            dataType : "xml",
            cache : false,
            data : {
                message : "msg_askmessg",
                os : KHL_parameter.os,
                usertype : KHL_parameter.usertype,
                ver : KHL_parameter.ver,
                messageid : msgid,
                type : 2
            }
        }).done(function(responsedata) {
            var source = context.createBufferSource(); 
            var buffer = context.createBuffer($.processStreamVoice(responsedata), true); //$.processStreamVoice, is base64 decode for responsedata
            source.buffer = buffer; 
            source.connect(context.destination); 
            source.noteOn(context.currentTime);
        });
    });

尝试更改此项:

 source.noteOn(context.currentTime);

到此:

source.noteOn ? source.noteOn(0) : source.start(0);

noteOn方法已被start取代,但Safari尚未跟上。而0的自变量相当于context.currentTime——两者都将立即开始播放。

相关内容

最新更新