JodusNodus / react-qr-reader

React component for reading QR codes from webcam.
https://jodusnodus.github.io/react-qr-reader
MIT License
1.14k stars 407 forks source link

Chrome on Android 11 freezes when closing the reader #185

Open Stofkat opened 3 years ago

Stofkat commented 3 years ago

Steps to reproduce

This appears to be a problem with the underlying MediaStreamTrack, the bug has already been reported in November 2020: https://bugs.chromium.org/p/chromium/issues/detail?id=1148532

I found out that introducing a small delay in MediaStreamTrack.stop helps as a workaround for this issue

I simply replaced line the this.stopCamera = streamTrack.stop.bind(streamTrack); with:


this.stopCamera = () => {
  setTimeout(() => {
    streamTrack.stop();
  }, 2000);
}
nastassiadanilova commented 3 years ago

Mostly the same issue https://bugs.chromium.org/p/chromium/issues/detail?id=1138823. Just to track how the progress is going.

One of the possible solutions https://github.com/twilio/twilio-video-app-react/issues/355#issuecomment-780368725

joobacca commented 3 years ago

@Stofkat Where do you define the streamTrack object?

joobacca commented 3 years ago

@Stofkat Where do you define the streamTrack object?

In case anyone stumbles upon the same problem, I solved it using the snippet @nastassiadanilova linked:

const video = qrReaderRef.current.els.preview;
video.srcObject = null;
navigator.mediaDevices
  .getUserMedia({
    video: true,
  })
  .then(mediaStream => {
     mediaStream.getVideoTracks().forEach(track => {
      mediaStream.removeTrack(track);
      track.stop();
    });
  });
ZanekShaw commented 1 year ago

I have this issue but need help implementing the patch you describe. Can you please explain further?