react-media-recorder icon indicating copy to clipboard operation
react-media-recorder copied to clipboard

stopRecording doesn't clear the recording icon in the tab

Open avastamin opened this issue 3 years ago • 10 comments

I used stopRecording to stop MediaRecorder stream. The red "recording" icon appears in the Chrome tab on start, but doesn't go away on stop.

The icon looks like this: https://i.stack.imgur.com/a0kZn.png

avastamin avatar Feb 14 '22 12:02 avastamin

Setting stopStreamsOnStop: true should work fine

itsjuanmatus avatar Jun 29 '22 06:06 itsjuanmatus

Even using stopStreamsOnStop: true isn't working for me. My settings:

const { startRecording, stopRecording } = useReactMediaRecorder({
    audio: true,
    video: false,
    askPermissionOnMount: true,
    stopStreamsOnStop: true,
    blobPropertyBag: {
      type: 'audio/webm',
    },
    onStop: (blobUrl, blob) => {
      updateBlob(blob);
    },
  });

mathewcst avatar Jul 01 '22 13:07 mathewcst

This is my code and it works fine:

const { startRecording, stopRecording, mediaBlobUrl, clearBlobUrl, status } =
    useReactMediaRecorder({
      mediaRecorderOptions: {
        mimeType: 'audio/wav', 
      },
      stopStreamsOnStop: true,
    });

itsjuanmatus avatar Jul 02 '22 14:07 itsjuanmatus

@mathewcst I did not use the onStop function, and instead used a useEffect and the mediaBlobUrl to update the blob.

useEffect(() => {
    if (mediaBlobUrl) { ... } 
}, [mediaBlobUrl])

itsjuanmatus avatar Jul 02 '22 15:07 itsjuanmatus

Fixed. Removing askPermissionOnMount: true gets rid of the icon.

mathewcst avatar Jul 12 '22 19:07 mathewcst

The icon disappears on Google Chrome, but it doesn't disappear on iOS Safari.

It seems to fully remove the icon on Safari, you need to call:

stream.getAudioTracks()[0].stop();

You can test it out here: https://codepen.io/jgthms/pen/vYrYzJE

What is weird is that it seems that this library is exactly doing this: https://github.com/0x006F/react-media-recorder/blob/c6c8a3522a6c15bb30fdd23f7016171cb5e787db/src/index.ts#L276

But somehow, the recording icon remains visible even after calling stopRecording(): IMG_71E1948FC097-1

Any ideas?

jgthms avatar Oct 27 '22 12:10 jgthms

Ok I found a workaround: use a custom MediaStream and use it to stop all audio tracks yourself.

// Need to use a ref to keep a reference between re-renders
const myCustomStream = useRef(null);

// When using the react-media-recorder hook, pass the customMediaStream
const {
  status,
  error,
  startRecording,
  stopRecording,
  // etc.
} = useReactMediaRecorder({
  audio: true,
  video: false,
  customMediaStream: myCustomStream.current,
 // etc.
});

// When asking for permission, store the stream that is returned
const handleAskForMicPermissions = useCallback(async () => {
  if (typeof window === "undefined") {
    return;
  }

  myCustomStream.current = navigator.mediaDevices.getUserMedia({
    audio: true,
    video: false,
  });

  // etc.
}, []);

// When stopping the recording, stop all audio tracks
const handleStop = useCallback(async () => {
  stopRecording();
  const stream = await myCustomStream.current;
  stream.getAudioTracks()[0].stop();
}, [stopRecording, myCustomStream]);

Hope this helps!

jgthms avatar Nov 04 '22 22:11 jgthms

I'm having the above issue on mobile only. @jgthms do you know if the above fix worked on mobile (eg IOS on chrome or safari?)

jasondainter avatar Nov 04 '23 19:11 jasondainter

Hi there can any one tell me what to do in the end cauz I'm confused.

amrmagdygamal avatar Jan 22 '24 09:01 amrmagdygamal

I'm having the above issue on mobile only. @jgthms do you know if the above fix worked on mobile (eg IOS on chrome or safari?)

Sorry, I don't remember, but I think it did.

jgthms avatar Jan 22 '24 14:01 jgthms