Index: ssts-web/src/main/webapp/disinfectsystem/test/takeVideoAndImg.js =================================================================== diff -u -r37893 -r37896 --- ssts-web/src/main/webapp/disinfectsystem/test/takeVideoAndImg.js (.../takeVideoAndImg.js) (revision 37893) +++ ssts-web/src/main/webapp/disinfectsystem/test/takeVideoAndImg.js (.../takeVideoAndImg.js) (revision 37896) @@ -7,6 +7,7 @@ var durationTime; var base64DataBig2; var times = null; +var newStream = null; //默认最高分辨率 var maxWidth = 2048; @@ -188,9 +189,7 @@ * @param stream {MediaStream} - 需要关闭的流 */ closeStream: function (stream) { - if (typeof stream.stop === 'function') { - stream.stop(); - } + stream.getVideoTracks()[0].stop(); } }; @@ -202,7 +201,9 @@ if (width && height) { videoObj = { width: width, height: height } } - + if(newStream){ + MediaUtils.closeStream(newStream) + } MediaUtils.getUserMedia(videoObj, false, function (err, stream) { if (err) { if (err == 'OverconstrainedError') { @@ -211,24 +212,13 @@ throw err; } } else { - video.srcObject = stream; - videoShow.srcObject = stream; + newStream = stream; var videoTrack = stream.getVideoTracks()[0]; - // 获取摄像头的设置 - var settings = videoTrack.getSettings(); var getCapabilities = videoTrack.getCapabilities(); maxWidth = width || getCapabilities.width.max; maxHeight = height || getCapabilities.height.max; - canvasBig.setAttribute('width', maxWidth); - canvasBig.setAttribute('height', maxHeight); - $('#video').css({ - width: maxWidth + 'px', - height: maxHeight + 'px', - display: 'none' - }) - video.play(); - videoShow.play(); if (isFirst) { + reloadUserMedia(maxWidth,maxHeight); var html = ''; if (maxWidth > 4096) { html += ''; @@ -268,6 +258,24 @@ } html += ''; $('#changeResolution').html(html); + }else { + video.srcObject = stream; + videoShow.srcObject = stream; + var videoTrack = stream.getVideoTracks()[0]; + // 获取摄像头的设置 + var settings = videoTrack.getSettings(); + var getCapabilities = videoTrack.getCapabilities(); + maxWidth = width || getCapabilities.width.max; + maxHeight = height || getCapabilities.height.max; + canvasBig.setAttribute('width', maxWidth); + canvasBig.setAttribute('height', maxHeight); + $('#video').css({ + width: maxWidth + 'px', + height: maxHeight + 'px', + display: 'none' + }) + video.play(); + videoShow.play(); } } });