代码之家  ›  专栏  ›  技术社区  ›  VikR

WebRTC with Agora.io:切换摄像头?

  •  2
  • VikR  · 技术社区  · 8 年前

    我正在使用Agora.io构建一个web应用程序。我希望能够在客户的智能手机上从前置摄像头切换到后置摄像头。我已经看了好几年了 switchCamera

    switchCamera();
    myAgoraClient.switchCamera();
    localStream.switchCamera();
    

    他们都投了一个球 no such function

    2 回复  |  直到 8 年前
        1
  •  2
  •   siniradam    7 年前

    你可以这样做 switchDevice 中的方法 2.5 SDK

    switchDevice(类型:string,设备ID:string,onSuccess:function, onFailure:函数):void

    localStream.switchDevice("video", "<deviceid>", console.log,console.log)
    

    我应该做这项工作。我也在尝试同样的东西,但示例中包含旧的2.4 js sdk,您需要专门下载^2.5

        2
  •  1
  •   Galaxy    7 年前

    但是,可以通过以下方式创建摄影机列表:

    AgoraRTC.getDevices(function(devices){
      cameras = devices.filter(device => device.kind === 'videoinput');
    });
    

    然后给switchCamera一个实现:

    function switchCamera(){
        cameraIndex = (++cameraIndex) % cameras.length;
    }
    

    cameras[cameraIndex].deviceId 作为 cameraId

    推荐文章