加载声音(XMLHttpRequest)并显示播放控件(html5音频播放器)

时间:2015-05-19 08:37:08

标签: javascript html5 html5-canvas html5-audio

我需要在浏览器中添加html5网络音频播放器(带有HTML页面控件)。 怎么做到了?

 function loadSound(url) {
        var request = new XMLHttpRequest();
        request.open('GET', url, true);
        request.responseType = 'arraybuffer';

        // When loaded decode the data
        request.onload = function() {

            // decode the data
            context.decodeAudioData(request.response, function(buffer) {
                // when the audio is decoded play the sound
                if (request.response) {
                    
                }
   
                playSound(buffer);
                
            }, onError);
        }
        request.send();
    }

loadSound("hello.mp3");

    function playSound(buffer) {
        sourceNode.buffer = buffer;
        sourceNode.start(0);
    }

0 个答案:

没有答案