Load sound (XMLHttpRequest) and show play controls (html5 audio player)

I need to add html5 web audio player (with controls on html page) for loaded mp3 song to browser.
How a can do it?

 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);
    }


Source: html5

Leave a Reply