admin管理员组文章数量:1410717
Problem Statement
Hi, I want to add support for audio recording using MediaRecorder
API in my app for IE 11 and Safari, but couldn’t figure anything so far. Are there any polyfills available that can help me add support for the same in these browsers?
Safari:
I can see Safari does have MediaRecorder
API supported under experimental features, but even that doesn’t seem to work properly despite giving a proper mime type of audio/webm
, it always returns a blob of video/mp4
mime type.
IE 11:
It's an ancient piece of rubbish, that's all I can say :)
Code:
const stream = await navigator.mediaDevices.getUserMedia({
audio: true,
video: false,
})
const mimeType = 'audio/webm'
// check if above mime type is supported in browser and instantiate recorder
if (MediaRecorder.isTypeSupported(mimeType)) {
this.recorder = new MediaRecorder(this.stream, { mimeType })
} else {
this.recorder = new MediaRecorder(this.stream)
}
recorder.start()
NOTE: Please don't ask to ditch these browsers as they are my requirement :)
Problem Statement
Hi, I want to add support for audio recording using MediaRecorder
API in my app for IE 11 and Safari, but couldn’t figure anything so far. Are there any polyfills available that can help me add support for the same in these browsers?
Safari:
I can see Safari does have MediaRecorder
API supported under experimental features, but even that doesn’t seem to work properly despite giving a proper mime type of audio/webm
, it always returns a blob of video/mp4
mime type.
IE 11:
It's an ancient piece of rubbish, that's all I can say :)
Code:
const stream = await navigator.mediaDevices.getUserMedia({
audio: true,
video: false,
})
const mimeType = 'audio/webm'
// check if above mime type is supported in browser and instantiate recorder
if (MediaRecorder.isTypeSupported(mimeType)) {
this.recorder = new MediaRecorder(this.stream, { mimeType })
} else {
this.recorder = new MediaRecorder(this.stream)
}
recorder.start()
NOTE: Please don't ask to ditch these browsers as they are my requirement :)
Share Improve this question asked Jul 20, 2020 at 7:32 Vinay SharmaVinay Sharma 3,8176 gold badges38 silver badges69 bronze badges1 Answer
Reset to default 6Safari Support:
I was able to add support for MediaRecorder
API in Safari by using Audio Recorder Polyfill. You can check this NPM package here.
Steps (React JS):
- Install the package using
npm i audio-recorder-polyfill
- Add this piece of code in public/index.html. This will make sure that the polyfill is loaded only for the browsers which do not support
MediaRecorder
API.
<script>
// load this bundle only for browsers without MediaRecorder support
if (!window.MediaRecorder) {
document.write(
decodeURI('%3Cscript defer src="/polyfill.js">%3C/script>')
)
}
</script>
- Add this piece of code in src/index.tsx or src/index.js. This will assign this polyfill to MediaRecorder present in window object.
import AudioRecorder from 'audio-recorder-polyfill'
window.MediaRecorder = AudioRecorder
- If you are using Typescript, you might have to add type declarations in src/audio-recorder-polyfill.d.ts
declare module 'audio-recorder-polyfill'
本文标签: javascriptMediarecorder How to support audio recording on SafariIE 11Stack Overflow
版权声明:本文标题:javascript - Mediarecorder: How to support audio recording on Safari, IE 11? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744787645a2625098.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论