2017-02-07 5 views
0

このコードは昨日まで問題なく何ヶ月も働いていましたが、今日は動作を停止しました。私はGoogleがいくつかのコードを許可しなくなったと思うが、どちらがわからないのだろう。クロムウェブカメラ。昨日までそれは働いた(数ヶ月)、今日ではなく、何が起こったのですか?

Chromeでコードエラーが表示されません。

//<![CDATA[ 
 
window.onload=function(){ 
 
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; 
 

 
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL; 
 

 
var start = document.querySelector('#start'), 
 
    capture = document.querySelector('#capture'), 
 
    canvas = document.querySelector('canvas'), 
 
    ctx = canvas.getContext('2d'), 
 
    video = document.querySelector('video'); 
 

 
start.addEventListener('click', function() { 
 

 
    navigator.getUserMedia({ 
 
     video: true 
 
    }, function (stream) { 
 
     var src = window.URL.createObjectURL(stream); 
 
     video.src = src; 
 
    }, function (e) { 
 
     console.log(e); 
 
    }); 
 

 
    
 

 
}, false); 
 

 
    capture.addEventListener('click', function() { 
 
     ctx.drawImage(video, 0, 0, canvas.width, canvas.height); 
 
    }, false); 
 
}//]]>
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
 
    <title></title> 
 

 
</head> 
 

 
<body> 
 

 
<video autoplay></video> 
 
<canvas width="300" height="200"></canvas> 
 
    <button id="start">Start</button> 
 
<button id="capture">Capture</button> 
 
</body> 
 

 
</html>

+0

他のブラウザを試しましたか? –

+0

'https://'や 'localhost'を使用していない場合、Chromeはスクリプトがウェブカメラにアクセスすることを許可しません。 – TricksfortheWeb

+0

はい、私は同じ問題、他のブラウザを試しました。私はhttps://を使用します。スクリプトコードをbodyタグに移動するとコードが動作しますが、この場合は他のスクリプト(geolocalization)は動作しません。非常に奇妙な。 – alexiter

答えて

0

Iは、次のような問題を解決:

I変更 "window.onload =関数(){" "機能のウェブカメラ(){" および私は関数を呼び出しますbodyタグの "onload"から取得します。

もう一度すべての機能が使用できます。

しかし、なぜ私は理解していません。

関連する問題