0

我正在尝试在我的 iOS webRTC 应用程序中创建本地媒体流。请参阅下面的代码

let localStream = pcFactory.mediaStream(withLabel: "ARDAMS")!

let audio = pcFactory.audioTrack(withID: "ARDAMSa0")
localStream.addAudioTrack(audio!)

var device: AVCaptureDevice?
for captureDevice in AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo){
    if let captureDevice = captureDevice as? AVCaptureDevice{
        if captureDevice.position == AVCaptureDevicePosition.front{
            device = captureDevice
        }
    }
}

if let device = device{
    let capture = RTCVideoCapturer(deviceName: device.localizedName)
    let videoSource = pcFactory.videoSource(with: capture, constraints: nil)
    localVideoTrack = pcFactory.videoTrack(withID: "ARDAMSv0", source: videoSource)
    localStream.addVideoTrack(localVideoTrack)
}


self.peerConnection?.add(localStream)

localVideoTrack?.add(localVideoView)

一切正常,但是当我添加localVideoView到后localVideoTrack我得到一个错误:

-[RTCI420Frame nativeHandle]: unrecognized selector sent to instance 0x170010620

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RTCI420Frame nativeHandle]: unrecognized selector sent to instance 0x170010620'

所有代码都在主线程上运行,并且应用程序具有适当的权限和 plist 键。当我使用调试器逐行浏览代码时,一切似乎都运行正常。此代码取自 Obj-C AppRTC 演示,它刚刚被转换为 swift。我似乎找不到崩溃的 swift 项目和正在运行的 AppRTC 项目之间的区别。知道我做错了什么吗?我正在 64 位设备上进行测试。谢谢!

4

0 回答 0