mirror of
https://github.com/cnwhy/QRCode-decode.git
synced 2026-08-12 20:31:40 +08:00
v0.0.5
This commit is contained in:
+26
-23
@@ -16,7 +16,7 @@
|
||||
<div></div>
|
||||
|
||||
</body>
|
||||
<script type="text/javascript" src="../dist/qr-decode.js"></script>
|
||||
<script type="text/javascript" src="../dist/qr-decode.umd.js"></script>
|
||||
<script>
|
||||
document.getElementById('file').onchange = function (event) {
|
||||
var el = event.target;
|
||||
@@ -48,48 +48,51 @@
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
var video =document.getElementById('video');
|
||||
var videoBut =document.getElementById('videoBut');
|
||||
|
||||
var video = document.getElementById('video');
|
||||
var videoBut = document.getElementById('videoBut');
|
||||
var xc;
|
||||
videoBut.onclick = videoEnable;
|
||||
|
||||
function videoEnable() {
|
||||
var URL = window.URL || window.webkitURL;
|
||||
navigator.getUserMedia({
|
||||
video: true
|
||||
}, function (stream) {
|
||||
video.src = URL.createObjectURL(stream);// 将获取到的视频流对象转换为地址
|
||||
video.oncanplay = function(){
|
||||
videoPlay();
|
||||
video.width = video.videoWidth;
|
||||
video.height = video.videoHeight;
|
||||
}
|
||||
}, function (error) {
|
||||
alert(error.name || error);
|
||||
});
|
||||
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
||||
navigator.mediaDevices.getUserMedia({
|
||||
video: true
|
||||
}).then(function (stream) {
|
||||
video.srcObject = stream; // 用 srcObject 替代已废弃的 URL.createObjectURL(stream)
|
||||
video.oncanplay = function () {
|
||||
videoPlay();
|
||||
video.width = video.videoWidth;
|
||||
video.height = video.videoHeight;
|
||||
}
|
||||
}).catch(function (error) {
|
||||
alert(error.name || error);
|
||||
});
|
||||
} else {
|
||||
alert('当前浏览器不支持摄像头访问');
|
||||
}
|
||||
}
|
||||
|
||||
function videoStop(){
|
||||
function videoStop() {
|
||||
clearInterval(xc);
|
||||
video.pause();
|
||||
videoBut.innerText = '启动';
|
||||
videoBut.onclick = videoPlay;
|
||||
}
|
||||
function videoPlay(){
|
||||
function videoPlay() {
|
||||
video.play();
|
||||
videoBut.innerText = '停止';
|
||||
xc = setInterval(function(){
|
||||
try{
|
||||
xc = setInterval(function () {
|
||||
try {
|
||||
var txt = qrDecode.decodeByDom(video);
|
||||
var msg = document.createElement("div")
|
||||
msg.innerHTML = "识别到二维码: " + txt;
|
||||
document.body.appendChild(msg);
|
||||
videoStop();
|
||||
}catch(err){
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
},300)
|
||||
}, 300)
|
||||
videoBut.onclick = videoStop;
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user