Xcode在尝试使用AVMutableComposition时抛出此错误:

Cannot invoke 'addMutableTrackWithMediaType' with an argument list of type  '(mediaType: String, preferredTrackID: Int)'

代码:
    let mixComposition = AVMutableComposition()
    let videoTrack = mixComposition.addMutableTrackWithMediaType(mediaType: AVMediaTypeVideo, preferredTrackID: kCMPersistentTrackID_Invalid)

我们也尝试过:
    let mixComposition = AVMutableComposition()
    let videoTrack = mixComposition.addMutableTrackWithMediaType(mediaType: "AVMediaTypeVideo", preferredTrackID: kCMPersistentTrackID_Invalid)

    let mixComposition = AVMutableComposition()
    let videoTrack = mixComposition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: kCMPersistentTrackID_Invalid)

这些都不起作用,谷歌也没有任何帮助。是什么导致了这个错误?

最佳答案

这纠正了编译错误,尽管它对preferredTrackId使用了不同的值:

    var videoTrack = mixComposition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: CMPersistentTrackID())

07-26 09:37