- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我怀疑带有 iOS13 的 Xcode 11 无法正常工作 Xcode 10.2.1 与 iOS12.2 可以正常工作
我试图将两个音频文件合并为一个音频文件。
下面的代码在 Xcode 10.2.1 和 iOS 12.2 上运行良好,但现在在 Xcode 11 和 iOS13 上运行
@objc func applyMergeAudio(){
playmerge(audio1: Bundle.main.url(forResource: "audio0", withExtension: "mp3")!,audio2: Bundle.main.url(forResource: "Asteroid_Sound", withExtension: "mp3")!)
}
func playmerge(audio1: URL, audio2: URL)
{
let composition = AVMutableComposition()
let compositionAudioTrack1:AVMutableCompositionTrack = composition.addMutableTrack(withMediaType: AVMediaType.audio, preferredTrackID: CMPersistentTrackID())!
let compositionAudioTrack2:AVMutableCompositionTrack = composition.addMutableTrack(withMediaType: AVMediaType.audio, preferredTrackID: CMPersistentTrackID())!
let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let fileDestinationUrl = documentDirectoryURL.appendingPathComponent("resultmerge.m4a")
let filemanager = FileManager.default
if (!filemanager.fileExists(atPath: fileDestinationUrl.path))
{
do
{
try filemanager.removeItem(at: fileDestinationUrl)
}
catch let error as NSError
{
NSLog("Error: \(error)")
}
}
let avAsset1 = AVURLAsset(url: audio1, options: nil)
let avAsset2 = AVURLAsset(url: audio2, options: nil)
var tracks1 = avAsset1.tracks(withMediaType: AVMediaType.audio)
var tracks2 = avAsset2.tracks(withMediaType: AVMediaType.audio)
let assetTrack1:AVAssetTrack = tracks1[0]
let assetTrack2:AVAssetTrack = tracks2[0]
let duration1: CMTime = assetTrack1.timeRange.duration
let duration2: CMTime = assetTrack2.timeRange.duration
let timeRange1 = CMTimeRangeMake(start: CMTime.zero, duration: duration1)
let timeRange2 = CMTimeRangeMake(start: CMTime.zero, duration: duration2)
do
{
try compositionAudioTrack1.insertTimeRange(timeRange1, of: assetTrack1, at: CMTime.zero)
try compositionAudioTrack2.insertTimeRange(timeRange2, of: assetTrack2, at: CMTime.zero)
}
catch
{
print(error)
}
//below line force unwarp Version xcode 10.2.1 working fine with iOS12.2. but xcode 11 with iOS13 got crush . .
let assetExport = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetAppleM4A)
assetExport?.outputFileType = AVFileType.m4a
assetExport?.outputURL = fileDestinationUrl
assetExport?.exportAsynchronously(completionHandler:
{
//xcode 11 with iOS13 not fire this block but xcode 10.2.1 with iOS12.2 working fine.
print(fileDestinationUrl)
})
}
那么你会告诉我任何替代解决方案还是我错过了什么?。
最佳答案
与其说是答案,不如说是将所有这些都作为评论来传达是很困难的。
Per Apple ,AVAssetExportSession
上有一个函数,您可以调用名为 allExportPresets()
的函数,它将输出所有可用的预设。
您还可以使用 AVAsset
调用 exportPresets(compatibleWith:)
以查找与该特定 Assets 兼容的资源。
当我使用 iOS 12 调用 allExportPresets()
时,我得到以下输出:
["AVAssetExportPreset1920x1080", "AVAssetExportPresetLowQuality", "AVAssetExportPresetAppleM4A", "AVAssetExportPresetHEVCHighestQuality", "AVAssetExportPreset640x480", "AVAssetExportPreset3840x2160", "AVAssetExportPresetHEVC3840x2160", "AVAssetExportPresetHighestQuality", "AVAssetExportPreset1280x720", "AVAssetExportPresetMediumQuality", "AVAssetExportPreset960x540", "AVAssetExportPresetHEVC1920x1080"]
尽管使用 iOS 13 调用相同的函数,我得到:
[]
当我检查各种预设的支持页面时,我找不到任何说明它们已被弃用等的文档。
我可以稍后尝试测试,看看我是否可以添加到这里。
希望这至少可以提供一些目前的指导。
关于ios - 具有 outputFileType m4a 的 AVAssetExportSession 不适用于 iOS13,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58188197/
我是一名优秀的程序员,十分优秀!