fix:平板调用摄像头方法变动(先判断是否支持getUserMedia() API)
This commit is contained in:
parent
75e9b6c296
commit
ddb3c4743c
|
|
@ -28,10 +28,10 @@ export default {
|
|||
methods: {
|
||||
// 启动摄像头并开始扫描
|
||||
async startScanning() {
|
||||
try {
|
||||
alert("启动摄像头");
|
||||
// 请求用户的摄像头权限并获取视频流
|
||||
const stream = await navigator.mediaDevices.getUserMedia({
|
||||
if(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){
|
||||
alert("摄像头可用");
|
||||
// 请求用户的摄像头权限并获取视频流
|
||||
const stream = await navigator.mediaDevices.getUserMedia({
|
||||
video: { facingMode: 'environment' }, // 使用后置摄像头
|
||||
});
|
||||
|
||||
|
|
@ -41,9 +41,25 @@ export default {
|
|||
setTimeout(() => {
|
||||
this.scanQRCode();
|
||||
},1000)
|
||||
} catch (error) {
|
||||
console.error('无法访问摄像头:', error);
|
||||
}else{
|
||||
alert("摄像头不可用:浏览器不支持getUserMedia");
|
||||
}
|
||||
// try {
|
||||
// alert("启动摄像头");
|
||||
// // 请求用户的摄像头权限并获取视频流
|
||||
// const stream = await navigator.mediaDevices.getUserMedia({
|
||||
// video: { facingMode: 'environment' }, // 使用后置摄像头
|
||||
// });
|
||||
|
||||
// this.videoStream = stream;
|
||||
// this.$refs.videoElement.srcObject = stream;
|
||||
// alert("准备就绪");
|
||||
// setTimeout(() => {
|
||||
// this.scanQRCode();
|
||||
// },1000)
|
||||
// } catch (error) {
|
||||
// console.error('无法访问摄像头:', error);
|
||||
// }
|
||||
},
|
||||
|
||||
// 从视频流中提取每一帧图像并识别二维码
|
||||
|
|
|
|||
Loading…
Reference in New Issue