我使用SDAVAssetExportSession
将MPMedaiItem
转换为.m4a
文件并且效果很好。
链接:Here
这是我的代码,最终结果将是.m4a
文件,当传递fileName
时1.aac
此代码无效。
我不知道outputFileType
类型的.aac
传递的内容。
//MARK:- Export Function
func exportAssetNew(_ asset: AVAsset, fileName: String,startPost:Int64,endPost:Int64) {
//print("\(#function)")
//print("startPost : \(startPost) :: endPost : \(endPost)")
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let trimmedSoundFileURL = documentsDirectory.appendingPathComponent(fileName)
//print("creating export session for \(asset)")
newSession = SDAVAssetExportSession(asset: loadedAssets)
newSession.outputFileType = AVFileTypeAppleM4A
newSession.outputURL = trimmedSoundFileURL
newSession.audioSettings = [AVFormatIDKey : kAudioFormatMPEG4AAC,AVNumberOfChannelsKey : 2,AVSampleRateKey:44100,AVEncoderBitRateKey:128000]
let startTime = CMTimeMake(startPost, 1)
let stopTime = CMTimeMake(endPost, 1)
newSession.timeRange = CMTimeRangeFromTimeToTime(startTime, stopTime)
newSession.exportAsynchronously(completionHandler: {
if self.newSession.status == AVAssetExportSessionStatus.completed {
//print("New Export Complete : fileName: ",fileName)
if self.songPartsUrls.count == 0 {
self.songPartsUrls.append(trimmedSoundFileURL)
self.childUploadingIndex = 0
// print("Stime : ",Date().timeIntervalSince1970)
self.createRequestWithAWS(songNamePrefix: self.regionPrefix)
}else{
self.songPartsUrls.append(trimmedSoundFileURL)
if self.isGoUploadFromChild {
self.isGoUploadFromChild = false
self.createRequestWithAWS(songNamePrefix: self.regionPrefix)
}
}
self.startSplitingSongs()
} else if self.newSession.status == AVAssetExportSessionStatus.cancelled {
print("New Export Cancel")
} else {
print("Error: ",self.newSession.error.localizedDescription)
}
})
}
如果我在文件名中传递.aac
,则会给出错误:错误:无法写入输出文件
我想要的是,.aac
格式的输出结果文件,我查看了类文件,但我无法弄清楚在#39; .aac&#39的代码中要更改的内容;文件。
有没有人有任何想法?