Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to switch the camera once selected with the problem camera #433

Closed
itshsinyu opened this issue May 16, 2024 · 7 comments · Fixed by #435
Closed

Unable to switch the camera once selected with the problem camera #433

itshsinyu opened this issue May 16, 2024 · 7 comments · Fixed by #435
Labels

Comments

@itshsinyu
Copy link

Describe the bug:
There are three cameras available. The second one is already in use, but the first and third ones are fine.
When I switch to the second camera, which has a problem, and then switch back to the first or third camera, an error is displayed.
Uncaught (in promise) DOMException: Could not start video source

Screenshots:
select the first camera
image
switch the second camera([NotReadableError])
image
switch back to the first camera, got an error
image

Desktop (please complete the following information):
OS: Windows
Browser: Chrome(124.0.6367.207)

@gruhn
Copy link
Owner

gruhn commented May 17, 2024

Can you reproduce this issue on this more bare bones demo?

https://gruhn.github.io/vue-qrcode-reader/select-camera-demo.html

@itshsinyu
Copy link
Author

It can switch back the camera successfully on select-camera-demo.html.
I am wondering what the different settings are between this demo.html and full-demo.html?

@gruhn
Copy link
Owner

gruhn commented May 21, 2024

Maybe there is some race condition. It could be that you select a new camera but for some reason the old camera is not stopped, thus a camera is "still in use" and you are not allowed to request a different camera.

I just added some more console logging to the "full demo". It should look somewhat like this:

[vue-qrcode-reader] starting camera with constraints:  {"facingMode":"environment"}
[vue-qrcode-reader] calling getUserMedia
[vue-qrcode-reader] waiting for video element to load
[vue-qrcode-reader] video element loaded
[vue-qrcode-reader] camera ready
[vue-qrcode-reader] start scanning
[vue-qrcode-reader] stopping camera
[vue-qrcode-reader] stop scanning: video element readyState is 0
[vue-qrcode-reader] starting camera with constraints:  {"deviceId":"03d3debb17710ee26e8ace22e346314dda144614ee43525d2d58bee3b6f9b45b"}
[vue-qrcode-reader] calling getUserMedia
[vue-qrcode-reader] waiting for video element to load
[vue-qrcode-reader] video element loaded
[vue-qrcode-reader] camera ready
[vue-qrcode-reader] start scanning

In particular every starting camera ... line should always be followed by a stopping camera line before a new starting camera line is printed.

@itshsinyu
Copy link
Author

When I select a new camera on the "full-demo" page after choosing a problematic camera, the console does not show the message "[vue-qrcode-reader] stopping camera". The old camera is not stopped as you mentioned.
image

However, I'm curious why it works well on the "select-camera-demo" page. It seems the old camera is stopped and the new camera starts on this page. Does the qrcodestream component use different settings?
image

<template>
<select v-model="selectedDevice">
    <option
      v-for="device in devices"
      :key="device.label"
      :value="device"
    >
      {{ device.label }}
    </option>
  </select>
<qrcode-stream
      :constraints="{ deviceId: selectedDevice.deviceId }"
      :track="paintCenterText"
      @detect="onDetect"
      @error="onError"
  />
</template>

<script lang="ts" setup>
const selectedDevice = ref(null as MediaDeviceInfo | null);
const devices = ref([] as MediaDeviceInfo[]);

onMounted(async () => {
    devices.value = (await navigator.mediaDevices.enumerateDevices()).filter(
	({ kind }) => kind === 'videoinput'
    );
    if (devices.value.length > 0) {
        selectedDevice.value = devices.value[0]
    }
});
</script>

@gruhn
Copy link
Owner

gruhn commented May 22, 2024

Thanks for the detailed description and screenshots. I may have found the issue. Could you check if this preview deployment fixes your issue?

https://gruhn.github.io/vue-qrcode-reader/pr-preview/pr-435/demos/FullDemo.html

@itshsinyu
Copy link
Author

itshsinyu commented May 23, 2024

This preview deployment resolves the issue. Thank you very much!

gruhn added a commit that referenced this issue May 23, 2024
If `runStartTask` manages to start a camera but then errors,
the `taskQueue` is perpetually in an error state. Fixing that
by catching the error.

Closes #433
gruhn added a commit that referenced this issue May 23, 2024
If `runStartTask` manages to start a camera but then errors,
the `taskQueue` is perpetually in an error state. Fixing that
by catching the error.

Closes #433
Copy link

🎉 This issue has been resolved in version 5.5.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants