fix switch camara
This commit is contained in:
parent
e1962d79bb
commit
202318c169
1 changed files with 4 additions and 17 deletions
|
|
@ -392,25 +392,12 @@ async function switchCamera() {
|
|||
return
|
||||
}
|
||||
|
||||
const frontCameras = availableCameras.value.filter((device: any) =>
|
||||
identifyCameraType(device.label || '') === 'front'
|
||||
)
|
||||
const backCameras = availableCameras.value.filter((device: any) =>
|
||||
identifyCameraType(device.label || '') === 'back'
|
||||
)
|
||||
|
||||
let targetDevice
|
||||
if (currentCameraType.value === 'front' && backCameras.length > 0) {
|
||||
targetDevice = backCameras[0]
|
||||
} else if (frontCameras.length > 0) {
|
||||
targetDevice = frontCameras[0]
|
||||
} else {
|
||||
const nextIndex = (currentCameraIndex.value + 1) % availableCameras.value.length
|
||||
targetDevice = availableCameras.value[nextIndex]
|
||||
}
|
||||
// สลับแค่ระหว่างกล้อง 2 ตัวแรก (กล้องหน้าและหลังหลัก)
|
||||
const targetIndex = currentCameraIndex.value === 0 ? 1 : 0
|
||||
const targetDevice = availableCameras.value[targetIndex]
|
||||
|
||||
await camera.value?.changeCamera(targetDevice.deviceId)
|
||||
currentCameraIndex.value = availableCameras.value.indexOf(targetDevice)
|
||||
currentCameraIndex.value = targetIndex
|
||||
currentCameraType.value = identifyCameraType(targetDevice.label || '')
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue