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

在Swift的WebRTC中使用后置摄像头

  •  0
  • stevenpcurtis  · 技术社区  · 7 年前

    要在WebRTC中切换摄像头,我想选择正确的摄像头设备(后摄像头),然后使用RTCDevideoCapturer定义视频源。

    在目标C中,如下所示:

    RTCVideoCapturer *capturer = [RTCVideoCapturer capturerWithDeviceName:cameraID];
    RTCMediaConstraints *mediaConstraints = [self defaultMediaStreamConstraints];
    RTCVideoSource *videoSource = [_factory videoSourceWithCapturer:capturer constraints:mediaConstraints];
    localVideoTrack = [_factory videoTrackWithID:@"ARDAMSv0" source:videoSource];
    

    似乎RTCDevideoCapurer可用的唯一构造函数需要委托,即。

    let capturer = RTCVideoCapturer(delegate: <#T##RTCVideoCapturerDelegate#>)
    

    那么我如何翻译代码呢?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Govind Kumawat    7 年前

    Swift 3中的翻译

    var capturer = RTCVideoCapturer(deviceName: cameraID)
    var mediaConstraints: RTCMediaConstraints? = defaultMediaStreamConstraints()
    var videoSource: RTCVideoSource? = factory.videoSource(with: capturer, constraints: mediaConstraints)
    localVideoTrack = factory.videoTrack(withID: "ARDAMSv0", source: videoSource)
    

    RTCAVFoundationVideoSource类中有一个名为“useBackCamera”的“bool”属性( RTCAVFoundationVideoSource。h类 ). 可以使用此属性在前/后摄像头之间切换。

    //In  RTCAVFoundationVideoSource.h
    
    /** Returns whether rear-facing camera is available for use. */
    @property(nonatomic, readonly) BOOL canUseBackCamera;
    
    /** Switches the camera being used (either front or back). */
    @property(nonatomic, assign) BOOL useBackCamera;
    
    /** Returns the active capture session. */
    @property(nonatomic, readonly) AVCaptureSession *captureSession;