HTML5 & getUserMedia - Record Audio & Save to Web Server after Certain Time

前端 未结 1 1144
一生所求
一生所求 2020-12-08 12:32

I\'m having some difficulties with getUserMedia with HTML5 whilst developing my web page. This is the first time I\'ve tried to implement this to record a users audio input.

相关标签:
1条回答
  • 2020-12-08 13:17

    can use XMLHttpRequest

    function upload(blobOrFile) {
        var xhr = new XMLHttpRequest();
        xhr.open('POST', '/upload.aspx', true);
        xhr.onload = function (e) {
            var result = e.target.result;
        };
    
        xhr.send(blobOrFile);
    }
    
    // stop recording function calls the upload method
    // I am using recorder.js
    
    recorder.exportWAV(function (blob) {
        var url = URL.createObjectURL(blob);
        audio.src = url;
        audio.controls = true;
        var hf = document.createElement('a');
        hf.href = url;
        hf.download = new Date().toISOString() + '.wav';
        upload(blob);   
    });
    
    // on server side ASPX pageload - can save .wav file on server
    
    Request.SaveAs(Server.MapPath("/foo/" + "1" + ".wav"), false);
    
    0 讨论(0)
提交回复
热议问题