closeio / mic-recorder-to-mp3

Microphone Recorder to mp3
MIT License
244 stars 138 forks source link

Not Support iphone #21

Closed prakash50166 closed 4 years ago

prakash50166 commented 4 years ago

audio record start not working in iphone safari browser

a-sklyarov commented 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.

yeniv commented 4 years ago

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.

buzinas commented 4 years ago

This is fixed, but I didn't release a version yet. I'll do it soon!

mohammadgarmroodi commented 4 years ago

+1

buzinas commented 4 years ago

This was published under v2.2.2 and should be fixed. Thanks for your patience.

mohammadgarmroodi commented 4 years ago

still not working!

buzinas commented 4 years ago

Works for me. What version are you use, @mohammadgarmroodi ? Can you share a code sample?

harrymelka commented 4 years ago

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 !

sjOwOw commented 4 years ago

@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.

harrymelka commented 4 years ago

@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