Pārlūkot izejas kodu

修复选择摄像头问题

warrior 1 mēnesi atpakaļ
vecāks
revīzija
5e76ab5361
1 mainītis faili ar 20 papildinājumiem un 19 dzēšanām
  1. 20 19
      projects/live-app/src/services/live.service.ts

+ 20 - 19
projects/live-app/src/services/live.service.ts

@@ -587,26 +587,27 @@ export class LiveService {
 
   /* 切换摄像头 */
   async changeCamera() {
-    // const oldCameras = await AgoraRTC.getCameras(true);
+    const oldCameras = await AgoraRTC.getCameras(true);
     // console.log('oldCameras:', oldCameras);
-    // let newCamers = oldCameras.find(
-    //   (item: any) => item.deviceId !== this.currentUsedDevice.videoDevice
-    // );
-    // console.log(newCamers);
-    // newCamers &&
-    //   (await this.localTracks.videoTrack.setDevice(newCamers.deviceId));
-    // .then(() => {
-    //   this.tools['camera'] = !this.tools['camera'];
-    //   this.currentUsedDevice.videoDevice = newCamers.deviceId;
-    // })
-    // .catch((err: any) => {
-    //   console.log('set device error', err);
-    //   this.tools['camera'] = !this.tools['camera'];
-    //   this.currentUsedDevice.videoDevice = newCamers.deviceId;
-    //   this.alertTips('切换摄像头失败');
-    // });
-    await this.localTracks.videoTrack.setDevice({facingMode: this.tools['camera'] ? 'user' : 'environment'})
-    this.tools['camera'] = !this.tools['camera'];
+    let newCamers = oldCameras.find(
+      (item: any) => item.deviceId !== this.currentUsedDevice.videoDevice
+    );
+    console.log(newCamers);
+    newCamers &&
+      this.localTracks.videoTrack
+        .setDevice(newCamers.deviceId)
+        .then(() => {
+          this.tools['camera'] = !this.tools['camera'];
+          this.currentUsedDevice.videoDevice = newCamers.deviceId;
+        })
+        .catch((err: any) => {
+          console.log('set device error', err);
+          this.tools['camera'] = !this.tools['camera'];
+          this.currentUsedDevice.videoDevice = newCamers.deviceId;
+          // this.alertTips('切换摄像头失败');
+        });
+    // await this.localTracks.videoTrack.setDevice({facingMode: this.tools['camera'] ? 'user' : 'environment'})
+    // this.tools['camera'] = !this.tools['camera'];
     // this.currentUsedDevice.videoDevice = newCamers.deviceId;
     return true;
   }