44

I start and stop a 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:

enter image description here

My code looks like this:

const mediaRecorder = new MediaRecorder(stream);
...
// Recording icon in the tab becomes visible.
mediaRecorder.start();
...
// Recording icon is still visible.
mediaRecorder.stop();

I also have a mediaRecorder.onstop handler defined. It doesn't return anything or interfere with the event object.

What's the proper way to clear the "recording" indicator for a tab after starting and stopping a MediaRecorder instance?

3 Answers 3

91

This is because this recording icon is the one of getUserMedia streaming, not the one of MediaRecorder.
When you stop the MediaRecorder, the stream is still active.

To stop this gUM stream (or any other MediaStream), you'd call MediaStreamTrack.stop().

stream.getTracks() // get all tracks from the MediaStream
  .forEach( track => track.stop() ); // stop each of them

Fiddle since stacksnippets doesn't allow gUM even with https...

And an other fiddle where the stream is accessed through MediaRecorder.stream.

13
  • 4
    I tried this code but red icon still visible. Any idea? Commented Jan 22, 2019 at 7:40
  • @HarshPatel you may have to wait a few seconds for the icon to disappear. If it is still there, it means that you have an other MediaStream still running.
    – Kaiido
    Commented Jan 22, 2019 at 7:42
  • in any case if some other MediaStream running then Is there anyway to stop all the MediaStream? Yes I wait for some times but function gets executed and still red icon appears as it is Commented Jan 22, 2019 at 7:45
  • @HarshPatel I extanded my comment on your question.
    – Kaiido
    Commented Jan 22, 2019 at 7:48
  • I still didn't get the way to remove that icon. Can you help me in this? I am using this Library , I guess it is using web speech API Commented Jan 22, 2019 at 9:38
0

Stopping the tracks didn't work for me (the blinking icon was still on the tab) but this does:

media_stream.getTracks().forEach(track => {
  track.stop()
  track.enabled = false
})
  const audioContext = new AudioContext()
  audioContext.close
  const microphone = audioContext.createMediaStreamSource(media_stream)
  microphone.disconnect
0

This is an answer to the people still having problems implementing the answers above: you need to use the same stream you used to create the recording to stop it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.