ios - 合并两个音频文件失败

标签 ios swift avfoundation avassetexportsession

Domain=AVFoundationErrorDomain Code=-11838\"Operation Stopped\"UserInfo={NSLocalizedDescription=Operation Stopped, NSLocalizedFailureReason=该媒体不支持该操作。})")

{来源:caf lpcm,目的地:aiff 或 wav 或 caf}

代码如下:

        let composition = AVMutableComposition()
        self.prepareToCombineMedia(composition)

        let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetPassthrough)!

        let tmpFilePath = FileUtils.tempFile(ext: "caf")
        exportSession.outputURL = NSURL.fileURL(withPath: tmpFilePath)
        exportSession.outputFileType = AVFileTypeCoreAudioFormat
        exportSession.exportAsynchronously {
            if exportSession.status == .completed {
                print("completed")
                print(tmpFilePath)
                subscriber.onCompleted()
            } else {
                subscriber.onError(LeafError.runtime(message: exportSession.error.debugDescription))
                FileUtils.rm(tmpFilePath)
            }
        }

它只能合并到 m4a 或 mov。我需要 caf 或 wav 或 aiff 文件,帮助...

最佳答案

替换这一行:

let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetPassthrough)!

与:

let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetAppleM4A)

希望它会起作用

关于ios - 合并两个音频文件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43039019/

相关文章:

ios - 在不在手机上播放媒体的情况下在锁定屏幕中显示 Nowplaying item meta

iphone - ios 使用 AVFramework 捕获图像

iOS xcode 麦克风音量检测?

ios - 如何验证电子邮件地址

iOS 回合制匹配,推送通知不起作用,GKTurnBasedEventListener 函数未调用

macos - dyld:未加载库:@rpath/libswiftAVFoundation.dylib

objective-c - 对两个 UISlider 进行编程,使其不超过彼此的值

ios - 在 iOS 应用程序中使用 JSON 的最佳方式是什么?

swift - 推送通知 swift 3

swift - 使用逻辑运算符保护 let