加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

RecorderJS通过AJAX上传记录的blob

发布时间:2020-12-16 02:53:57 所属栏目:百科 来源:网络整理
导读:我正在使用Matt Diamond的recorder.js来浏览 HTML5音频API,感觉这个问题可能有一个明显的答案,但我找不到任何具体的文档. 问题:录制wav文件后,如何通过ajax将该wav发送到服务器?有什么建议??? 解决方法 如果你有blob,你需要把它变成一个url并通过ajax调
我正在使用Matt Diamond的recorder.js来浏览 HTML5音频API,感觉这个问题可能有一个明显的答案,但我找不到任何具体的文档.

问题:录制wav文件后,如何通过ajax将该wav发送到服务器?有什么建议???

解决方法

如果你有blob,你需要把它变成一个url并通过ajax调用运行url.

// might be nice to set up a boolean somewhere if you have a handler object
object = new Object();
object.sendToServer = true;

// You can create a callback and set it in the config object.
var config = {
   callback : myCallback
}

// in the callback,send the blob to the server if you set the property to true
function myCallback(blob){
   if( object.sendToServer ){

     // create an object url
     // Matt actually uses this line when he creates Recorder.forceDownload()
     var url = (window.URL || window.webkitURL).createObjectURL(blob);

     // create a new request and send it via the objectUrl
     var request = new XMLHttpRequest();
     request.open("GET",url,true);
     request.responseType = "blob";
     request.onload = function(){
       // send the blob somewhere else or handle it here
       // use request.response
     }
     request.send();
   }
}

// very important! run the following exportWAV method to trigger the callback
rec.exportWAV();

让我知道这是否有效..没有测试它但它应该工作.干杯!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读