任何帮助都会很棒……解决方法 使用AVFoundation怎么样?将音频文件导入AVAsset(合成等),然后您可以将其 – 设置首选持续时间 – 导出到文件.
我之前编写了一个将资产导出到文件的股票函数,你也可以指定一个audiomix.如下所示,它导出所有文件,但你可以将一个NSTimeRange添加到exporter.timeRange,然后你去.我没有测试过,但应该工作(?).另一种方法是在创建AVAsset轨道时调整时间范围.当然,出口商只处理m4a(AAC).对不起,如果这不是你想要的.
-(voID)exportAsset:(AVAsset*)asset tofile:(Nsstring*)filename overwrite:(BOol)overwrite withMix:(AVAudioMix*)mix {//NSArray* availablePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:asset];AVAssetExportSession* exporter = [AVAssetExportSession exportSessionWithAsset:asset presetname:AVAssetExportPresetAppleM4A];if (exporter == nil) { DLog(@"Failed creating exporter!"); return;}DLog(@"Created exporter! %@",exporter);// Set output file typeDLog(@"Supported file types: %@",exporter.supportedfileTypes);for (Nsstring* filetype in exporter.supportedfileTypes) { if ([filetype isEqualToString:AVfileTypeAppleM4A]) { exporter.outputfileType = AVfileTypeAppleM4A; break; }}if (exporter.outputfileType == nil) { DLog(@"Needed output file type not found? (%@)",AVfileTypeAppleM4A); return;}// Set outputURLNSArray* paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES);Nsstring* parentDir = [Nsstring stringWithFormat:@"%@/",[paths objectAtIndex:0]];Nsstring* outPath = [Nsstring stringWithFormat:@"%@%@",parentDir,filename];NSfileManager* manager = [NSfileManager defaultManager];if ([manager fileExistsAtPath:outPath]) { DLog(@"%@ already exists!",outPath); if (!overwrite) { DLog(@"Not overwriting,uh oh!"); return; } else { // Overwrite DLog(@"Overwrite! (delete first)"); NSError* error = nil; if (![manager removeItemAtPath:outPath error:&error]) { DLog(@"Failed removing %@,error: %@",outPath,error.description); return; } else { DLog(@"Removed %@",outPath); } }}NSURL* const outUrl = [NSURL fileURLWithPath:outPath];exporter.outputURL = outUrl;// Specify a time range in case only part of file should be exported//exporter.timeRange =if (mix != nil) exporter.audioMix = mix; // importantDLog(@"Starting export! (%@)",exporter.outputURL);[exporter exportAsynchronouslyWithCompletionHandler:^(voID) { // Export ended for some reason. Check in status Nsstring* message; switch (exporter.status) { case AVAssetExportSessionStatusFailed: message = [Nsstring stringWithFormat:@"Export Failed. Error: %@",exporter.error.description]; DLog(@"%@",message); [self showAlert:message]; break; case AVAssetExportSessionStatusCompleted: { /*if (playfileWhenExportFinished) { DLog(@"playfileWhenExportFinished!"); [self playfileAfterExport:exporter.outputURL]; playfileWhenExportFinished = NO; }*/ message = [Nsstring stringWithFormat:@"Export completed: %@",filename]; DLog(@"%@",message); [self showAlert:message]; break; } case AVAssetExportSessionStatusCancelled: message = [Nsstring stringWithFormat:@"Export cancelled!"]; DLog(@"%@",message); [self showAlert:message]; break; default: DLog(@"Export unhandled status: %d",exporter.status); break; } }];}总结
以上是内存溢出为你收集整理的cocoa-touch – 使用iOS修剪音频全部内容,希望文章能够帮你解决cocoa-touch – 使用iOS修剪音频所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)