fix: switch camera not working
This commit is contained in:
parent
c79cb3d52f
commit
96afa1fa50
@ -201,21 +201,29 @@ function onFileInput(event) {
|
|||||||
|
|
||||||
const video = ref(null)
|
const video = ref(null)
|
||||||
const facingMode = ref('environment')
|
const facingMode = ref('environment')
|
||||||
|
const stream = ref(null)
|
||||||
|
|
||||||
async function startCamera() {
|
async function startCamera() {
|
||||||
showCamera.value = true
|
showCamera.value = true
|
||||||
|
|
||||||
let stream = await navigator.mediaDevices.getUserMedia({
|
stream.value = await navigator.mediaDevices.getUserMedia({
|
||||||
video: {
|
video: {
|
||||||
facingMode: facingMode.value,
|
facingMode: facingMode.value,
|
||||||
},
|
},
|
||||||
audio: false,
|
audio: false,
|
||||||
})
|
})
|
||||||
video.value.srcObject = stream
|
video.value.srcObject = stream.value
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopStream() {
|
||||||
|
stream.value.getTracks().forEach((track) => track.stop())
|
||||||
|
showCamera.value = false
|
||||||
|
cameraImage.value = null
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchCamera() {
|
function switchCamera() {
|
||||||
facingMode.value = facingMode.value === 'environment' ? 'user' : 'environment'
|
facingMode.value = facingMode.value === 'environment' ? 'user' : 'environment'
|
||||||
|
stopStream()
|
||||||
startCamera()
|
startCamera()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user