我现在正在尝试使用AVPlayer(使用URL)播放的MP3文件进行导出,以便不必再次下载。
这是我的示例代码:
我已经尝试了每种outputFileType...
self.exporter = [[AVAssetExportSession alloc] initWithAsset:self.asset presetName:AVAssetExportPresetPassthrough];
}
NSError *error;
NSLog(@"export.supportedFileTypes : %@",self.exporter.supportedFileTypes);
// "com.apple.quicktime-movie",
// "com.apple.m4a-audio",
// "public.mpeg-4",
// "com.apple.m4v-video",
// "public.3gpp",
// "org.3gpp.adaptive-multi-rate-audio",
// "com.microsoft.waveform-audio",
// "public.aiff-audio",
// "public.aifc-audio",
// "com.apple.coreaudio-format"
self.exporter.outputFileType = @"public.aiff-audio";
self.exporter.shouldOptimizeForNetworkUse = YES;
NSURL *a = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:&error];
NSURL *url = [a URLByAppendingPathComponent:@"filename.mp3"];
NSString *filePath = [url absoluteString];
self.exporter.outputURL = url;
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]){
[self.exporter exportAsynchronouslyWithCompletionHandler:^{
if (self.exporter.status == AVAssetExportSessionStatusCompleted)
{
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]){
NSLog(@"File doesn't exist at path");
}else {
NSLog@"File saved!");
}
}
else if(self.exporter.status == AVAssetExportSessionStatusFailed){
NSLog(@"Failed");
}else if(self.exporter.status == AVAssetExportSessionStatusUnknown){
NSLog(@"Unknown");
}else if(self.exporter.status == AVAssetExportSessionStatusCancelled){
NSLog(@"Cancelled");
}else if(self.exporter.status == AVAssetExportSessionStatusWaiting){
NSLog(@"Waiting");
}else if(self.exporter.status == AVAssetExportSessionStatusExporting){
NSLog(@"Exporting");
}
NSLog(@"Exporter error! : %@",self.exporter.error);
}];
}}else{
NSLog(@"File already exists at path");
}
如果无法实现这一点,是否有任何解决方法?
另外,我可以更改音频文件的格式。与AVAudioPlayer一起使用的理想类型是什么?