nimiq / qr-scanner

Lightweight Javascript QR Code Scanner
https://nimiq.github.io/qr-scanner/demo
MIT License
2.35k stars 509 forks source link

Camera not closing on iOS #235

Open rpaugh opened 1 year ago

rpaugh commented 1 year ago

After launching the camera on iOS, the barcode is correctly scanned and processed in the background, the camera pauses letting you know this action took place, but the camera never closes. I have to manually close out of the camera to get back to my app that launched it. I am calling scanner.stop() during the setResult call:

` const scanner = new QrScanner(video, result => setResult(fileQrResult, result), { onDecodeError: error => { fileQrResult.textContent = error; fileQrResult.style.color = 'inherit'; }, highlightScanRegion: true, highlightCodeOutline: true }); scanner.setCamera('user');

function setResult(label, result) {
    scanner.stop();
    try {

... }`

Is there something else I need to do for the scanner to force close the camera after the scan?

Mikiewitch commented 10 months ago

Same thing happens on Android and Windows. Any luck with this issue?

Mikiewitch commented 10 months ago

Seems like this could help:

                const mediaStream = videoElement.srcObject;
                if (mediaStream instanceof MediaStream) {
                    const tracks = mediaStream.getTracks();
                    tracks.forEach(track => {
                        track.stop();
                    });

                    videoElement.srcObject = null;
                }
rpaugh commented 10 months ago

By "videoElement" are you referring to the video html tag?

Mikiewitch commented 10 months ago

Yes, the one you are passing as parameter to QrScanner constructor.