2

无法使用 WebRTC 从 UIImagePickerController 加载视频。使用保存的应用内捆绑文件,它可以工作,但如果我使用 UIImagePickerController

UIImagePickerControllerDelegate.imagePickerController(_:didFinishPickingMediaWithInfo:))

所以我像这样使用 mediaInfo:

(info[.mediaURL] as! URL).path

我用来开始捕获视频文件的这段代码

   public func startCaptureLocalVideoFile(name: String, renderer: RTCVideoRenderer) {
        print("startCaptureLocalVideoFile")

        stopLocalCapture()

        localRenderer = renderer
        videoCapturer = RTCFileVideoCapturer(delegate: videoSource)

        guard let capturer = videoCapturer as? RTCFileVideoCapturer else {
            print("WebRTCService can't get capturer")
            return
        }

        capturer.startCapturing(fromFileNamed: name) { error in
            print("startCapturing error ", error)
            return
        }

        localVideoTrack?.add(renderer)
    }

所以我得到了这个媒体信息:

info  [__C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerMediaURL): file:///private/var/mobile/Containers/Data/PluginKitPlugin/5F7A4469-5006-4590-8F59-396CD86A083B/tmp/trim.B46C5878-BAF2-432B-B627-9787D74CE7B0.MOV, __C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerMediaType): public.movie, __C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerReferenceURL): assets-library://asset/asset.MOV?id=33EECFB7-514A-435A-AA19-26A055FB9F06&ext=MOV]

这个错误:

startCapturing error  Error Domain=org.webrtc.RTCFileVideoCapturer Code=2001 "(null)" UserInfo={NSUnderlyingError=File /private/var/mobile/Containers/Data/PluginKitPlugin/5F7A4469-5006-4590-8F59-396CD86A083B/tmp/trim.B46C5878-BAF2-432B-B627-9787D74CE7B0.MOV not found in bundle}

似乎它只适用于它Bundle.main,但我们不能写入它。

我做对了吗?也许还有另一种方法可以做到这一点?谢谢您的帮助!

4

0 回答 0