@@ -6,7 +6,12 @@ const audioOutputSelect = document.querySelector('select#audioOutput');
66const videoSelect = document . querySelector ( 'select#videoSource' ) ;
77const selectors = [ audioInputSelect , audioOutputSelect , videoSelect ] ;
88
9- audioOutputSelect . disabled = ! ( 'sinkId' in HTMLMediaElement . prototype ) ;
9+ let video = document . querySelector ( 'video' ) ;
10+ let canvas = document . getElementById ( 'canvas' ) ;
11+ let context1 = canvas . getContext ( '2d' ) ;
12+ let photograph = document . querySelector ( "#photograph" )
13+
14+ // audioOutputSelect.disabled = !('sinkId' in HTMLMediaElement.prototype);
1015
1116function gotDevices ( deviceInfos ) {
1217 // Handles being called several times to update labels. Preserve values.
@@ -85,14 +90,14 @@ function start() {
8590 track . stop ( ) ;
8691 } ) ;
8792 }
88- const audioSource = audioInputSelect . value ;
93+ // const audioSource = audioInputSelect.value;
8994 const videoSource = videoSelect . value ;
9095 const constraints = {
91- audio : {
92- deviceId : audioSource ? {
93- exact : audioSource
94- } : undefined
95- } ,
96+ // audio: {
97+ // deviceId: audioSource ? {
98+ // exact: audioSource
99+ // } : undefined
100+ // },
96101 video : {
97102 deviceId : videoSource ? {
98103 exact : videoSource
@@ -102,9 +107,23 @@ function start() {
102107 navigator . mediaDevices . getUserMedia ( constraints ) . then ( gotStream ) . then ( gotDevices ) . catch ( handleError ) ;
103108}
104109
105- audioInputSelect . onchange = start ;
106- audioOutputSelect . onchange = changeAudioDestination ;
110+ // audioInputSelect.onchange = start;
111+ // audioOutputSelect.onchange = changeAudioDestination;
107112
108113videoSelect . onchange = start ;
109114
110- start ( ) ;
115+ start ( ) ;
116+
117+ //拍照
118+ photograph . addEventListener ( "click" , ( ) => {
119+ // if (!this.isOpenCamera) return alert("请开启摄像机权限")
120+
121+ let img = new Image ( ) ;
122+ img . src = "" ;
123+ img . onload = function ( ev ) {
124+ context1 . drawImage ( img , 0 , 0 ) ;
125+ }
126+
127+ context1 . drawImage ( video , 50 , 50 ) ; //将video对象内指定的区域捕捉绘制到画布上指定的区域,实现拍照。
128+ context1 . drawImage ( img , 50 , 50 ) ;
129+ } )
0 commit comments