From 4a36f0d6548c0af75b53c84f998eff22090fe1b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=A4=20=E6=A2=81?= Date: Sun, 12 Jun 2022 18:22:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=8D=E7=85=A7=E6=B5=8B=E8=AF=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/StuInfoBasic/Index.cshtml | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuInfoBasic/Index.cshtml b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuInfoBasic/Index.cshtml index 673ee3a27..5e901acba 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuInfoBasic/Index.cshtml +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuInfoBasic/Index.cshtml @@ -218,7 +218,39 @@ $("#video").hide(); //隐藏拍照框 $("#showImg").show(); //将拍照结果显示 }); + // 遍历所有的设备,包括视频和音频设备,找到摄像头 + function gotDevices(deviceInfos) { + console.log(deviceInfos); + } + function handleError(error) { + console.log('Error: ', error); + } + + //访问用户媒体设备的兼容方法 + function getUserMedia(constraints, success, error) { + if (navigator.mediaDevices.getUserMedia) { + //最新的标准API + navigator.mediaDevices.getUserMedia(constraints).then(success).catch(error); + } else if (navigator.webkitGetUserMedia) { + //webkit核心浏览器 + navigator.webkitGetUserMedia(constraints, success, error) + } else if (navigator.mozGetUserMedia) { + //firfox浏览器 + navigator.mozGetUserMedia(constraints, success, error); + } else if (navigator.getUserMedia) { + //旧版API + navigator.getUserMedia(constraints, success, error); + } + } + function success(stream) { + console.log(stream); + window.localStorage.setItem('first', "false"); + window.location.reload(); + } + function error(error) { + console.log(`访问用户媒体设备失败${error.name}, ${error.message}`); + } //请求拍照 $("#takeAgain").bind("click", function () { takePhoto(); @@ -227,7 +259,23 @@ //开始拍照 function takeImg() { $(".tailoring-container").toggle(); - takePhoto(); + //首次运行引导用户,信任域名 + var first = window.localStorage.getItem('first'); + if (first == null) { + if (navigator.mediaDevices.getUserMedia || navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia) { + //调用用户媒体设备, 访问摄像头 + getUserMedia({ video: { width: 480, height: 320 } }, success, error); + } else { + alert('不支持访问用户媒体'); + } + } + if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) { + console.log('menumerateDevices is not supported!'); + } else { + navigator.mediaDevices.enumerateDevices() + .then(gotDevices).catch(handleError); + } + //takePhoto(); } //请求摄像头