我使用媒体记录器(html5-audio-record)在 android webview 中录制音频,这是可行的,但有时我没有收到任何数据并且 blob 没有改变!我关闭了我的 android 活动,并且每次测试的状态都是固定的,但是第一次运行良好,下一次运行不正常。为什么当我停止录制时 e.data 为空?
JS代码:
navigator.mediaDevices.getUserMedia(
{audio : true}
).then(function(stream) {
chunks[index] = [];
recorder[index] = new MediaRecorder(stream);
recorder[index].ignoreMutedMedia = false;
recorder[index].ondataavailable = function(e) {
chunks[index].push(e.data);
if (recorder[index].state == 'inactive') {
var blob = new Blob(chunks[index], { type: 'audio/webm' });
recorder[index].ondataavailable = null;
uploadFile(blob, index);
}
};
if(recorder[index] != 'recording')
recorder[index].start(1000); //recorder[index].start();
}).catch(function(index) {
microphoneError();
});