@@ -17,7 +17,6 @@ export class DocumentCaptureComponent implements AfterViewInit {
17
17
tags : string [ ] = [ ] ;
18
18
sourceText ! : string ;
19
19
videoDevices ! : MediaDeviceInfo [ ] ;
20
- selectedVideoDevice ! : MediaDeviceInfo | null ;
21
20
22
21
constructor ( ) {
23
22
this . captures = [ ] ;
@@ -26,36 +25,33 @@ export class DocumentCaptureComponent implements AfterViewInit {
26
25
ngAfterViewInit ( ) {
27
26
this . video = this . videoElement . nativeElement ;
28
27
this . canvas = this . canvasElement . nativeElement ;
28
+ this . getCameraList ( ) ;
29
29
}
30
30
31
- startCamera ( ) {
31
+ getCameraList ( ) {
32
32
navigator . mediaDevices . enumerateDevices ( ) . then ( devices => {
33
+ console . log ( devices )
33
34
this . videoDevices = devices . filter ( device => device . kind === 'videoinput' ) ;
34
- if ( this . videoDevices . length > 0 ) {
35
- this . selectedVideoDevice = this . videoDevices [ 0 ] ; // Select the first available video device by default
36
- this . startMediaStream ( ) ;
37
- } else {
35
+ if ( this . videoDevices ?. length == 0 ) {
38
36
console . error ( 'No video devices found.' ) ;
39
37
}
40
38
} ) ;
41
39
}
42
40
43
41
changeCamera ( device : MediaDeviceInfo ) {
44
- this . selectedVideoDevice = device ;
45
- this . startMediaStream ( ) ;
42
+ this . startMediaStream ( device ) ;
46
43
}
47
44
48
- startMediaStream ( ) {
49
- if ( this . selectedVideoDevice ) {
50
- navigator . mediaDevices . getUserMedia ( { video : { deviceId : this . selectedVideoDevice . deviceId } } )
51
- . then ( stream => {
52
- this . video . srcObject = stream ;
53
- this . video . play ( ) ;
54
- } )
55
- . catch ( err => {
56
- console . error ( 'Error accessing video stream:' , err ) ;
57
- } ) ;
58
- }
45
+ startMediaStream ( device : MediaDeviceInfo ) {
46
+ this . video . load ( ) ;
47
+ navigator . mediaDevices . getUserMedia ( { video : { deviceId : device . deviceId } } )
48
+ . then ( stream => {
49
+ this . video . srcObject = stream ;
50
+ this . video . play ( ) ;
51
+ } )
52
+ . catch ( err => {
53
+ console . error ( 'Error accessing video stream:' , err ) ;
54
+ } ) ;
59
55
}
60
56
61
57
capture ( ) {
0 commit comments