Closed prakash50166 closed 4 years ago
I struggled with this last week. AudioContext
is in suspended
state by default on Safari and must be resumed in direct response to a user interaction, e.g. in an onclick
event handler. Also, make sure it really is directly in the onclick
handler and not in a promise because that won't work. I don't think there is a way of achieving this without code changes at the moment. I ended up significantly changing the code to fit my purpose.
I'm far from an AudioContext
expert, but I found adding the following got this library working for me on iPhone.
window.AudioContext = window.AudioContext || window.webkitAudioContext;
I sometimes encounter crackling audio on mobile though. Still looking for a fix for that.
This is fixed, but I didn't release a version yet. I'll do it soon!
+1
This was published under v2.2.2 and should be fixed. Thanks for your patience.
still not working!
Works for me. What version are you use, @mohammadgarmroodi ? Can you share a code sample?
Hey,
I manage to make it work on all the browser (safari included) with
startRecording = () => {
// Start recording. Browser will request permission to use your microphone.
recorder
.start()
.then(() => {
this.setState({
isRecording: true,
});
// TODO: animation voice
})
.catch(e => {
console.error(e);
});
};
stopRecording = () => {
// Once you are done singing your best song, stop and get the mp3.
this.setState({
isRecording: false,
});
recorder
.stop()
.getMp3()
.then(([buffer, blob]) => {
const file = new File(buffer, 'voice.mp3', {
type: blob.type,
lastModified: Date.now(),
});
this.postVoice(file);
})
.catch(e => {
alert('We could not retrieve your message');
console.log(e);
});
};
and by adding
window.AudioContext = window.AudioContext || window.webkitAudioContext;
at my init index file
I updated the lib
"mic-recorder-to-mp3": "2.2.2",
but it still doesn't work on safari in my iPhone (I don't know for android phone yet)
How did you manage to make it work on iPhone ?
Thanks !
@buzinas
hello, I also don't working for iPhone. Version 2.2.2 used.
But it works on CDN(https://unpkg.com/mic-recorder-to-mp3@2.2.2/dist/index.js). LOL
I think NPM package distribution is wrong.
@buzinas @sjOwOw Hey,
I tried everything, the npm package, all the modifications, the CDN and it still not working.
I used https://jsfiddle.net/8u5fbpx6/1/ as an example and on iPhone's safari it ask me the permission to access the microphone, but when I use mine it don't even ask for it.
Do you have an idea about it ?
Thanks
audio record start not working in iphone safari browser