html未找到音频文件夹,【已解决】html5中MediaRecorder的dataavailable没有执行获取不到录音数据...

本文档记录了在HTML5中使用MediaRecorder时遇到的问题,即dataavailable事件未触发,导致无法获取录音数据。通过尝试不同设置,如修改mimeType、添加timeslice参数,最终发现只有在调用stop方法时,dataavailable事件才会被触发,从而能够成功获取到录音数据。解决方案是确保正确配置MediaRecorder,并使用stop方法结束录音。
摘要由CSDN通过智能技术生成

折腾:

期间,用相关代码:    function testMediaRecorder(mediaStream){

console.log("testMediaRecorder: mediaStream=%o", mediaStream);

const options = {mimeType: 'audio/webm'};

if (MediaRecorder.isTypeSupported(options.mimeType)) {

console.log("support options=%o", options);

} else {

console.log(options.mimeType + ' is not Supported');

}

const recordedChunks = [];

const mediaRecorder = new MediaRecorder(mediaStream, options);

console.log("mediaRecorder=%o", mediaRecorder);

mediaRecorder.addEventListener('dataavailable', function(e) {

console.log("dataavailable: e.data.size=%d, e.data=%o", e.data.size, e.data);

if (e.data.size > 0) {

recordedChunks.push(e.data);

console.log("recordedChunks=%o", recordedChunks);

}

if (shouldStop === true && stopped === false) {

mediaRecorder.stop();

stopped = true;

console.log("stopped=%s", stopped);

}

});

mediaRecorder.addEventListener('stop', function() {

// downloadLink.href = URL.createObjectURL(new Blob(recordedChunks));

// downloadLink.download = 'acetest.wav';

var blobFile = URL.createObjectURL(new Blob(recordedChunks));

console.log("blobFile=%o", blobFile);

$("#downloadSpeakAudio").attr("href", speakAudioFilename);

var curDate = new Date();

console.log("curDate=%o", curDate);

var curDatetimeStr = curDate.Format("yyyyMMdd_HHmmss");

console.log("curDatetimeStr=%o", curDatetimeStr);

var speakAudioFilename = curDatetimeStr + ".wav"

console.log("speakAudioFilename=%o", speakAudioFilename);

$("#downloadSpeakAudio").attr("download", speakAudioFilename);

});

console.log("before start: mediaRecorder.state=%s", mediaRecorder.state);

mediaRecorder.start();

// mediaRecorder.start(100);

console.log("after  start: mediaRecorder.state=%s", mediaRecorder.state);

}

但是始终无法执行到:dataavailable

从而无法得到麦克风录音的数据

MediaRecorder dataavailable not work

chrome中是可以开启摄像头的:

22d560566d8ffa1beb7ff04eed718009.png

Chrome’s experimental Web Platform Features enabled

MediaRecorder voice

js MediaRecorder voice

去调试:console.log("before start: mediaRecorder.state=%s", mediaRecorder.state);

mediaRecorder.start();

console.log("after start: mediaRecorder.state=%s", mediaRecorder.state);

state是对的:before start: mediaRecorder.state=inactive

main.js:196 after  start: mediaRecorder.state=recording

MediaRecorder dataavailable not fire

“2.2. Attributes

stream, of type MediaStream, readonly

The MediaStream to be recorded.

mimeType, of type DOMString, readonly

The MIME type [RFC2046] that has been selected as the container for recording. This entry includes all the parameters to the base mimeType. The UA should be able to play back any of the MIME types it supports for recording. For example, it should be able to display a video recording in the HTML tag. The default value for this property is platform-specific.

mimeType specifies the media type and container format for the recording via a type/subtype combination, with the codecs and/or profiles parameters [RFC6381] specified where ambiguity might arise. Individual codecs might have further optional specific parameters.

state, of type RecordingState, readonly

The current state of the MediaRecorder object. When the MediaRecorder is created, the UA MUST set this attribute to i

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值