gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 15:04:21 27 4
gpt4 key购买 nike

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

在 Objective C 中,这看起来像下面这样:

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

似乎 RTCVideoCapurer 可用的唯一构造函数需要委托(delegate),即

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

那么我该如何翻译代码呢?

最佳答案

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 类 (RTCAVFoundationVideoSource.h) 中有一个名为“useBackCamera”的“bool”属性。您可以使用此属性在前置/后置摄像头之间切换。

//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;

关于swift - 在 Swift 的 WebRTC 中使用后置摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48656026/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com