0

我正在使用下面的代码从库中获取音频以进行修剪

在这里我的问题是我能够获得音频但是需要很长时间才能获得音频

AAVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:appDelegate.librarySongURL options:nil];

NSLog (@"Core Audio %@ directly open library URL %@",
       coreAudioCanOpenURL (appDelegate.librarySongURL) ? @"can" : @"cannot",
       appDelegate.librarySongURL);

NSLog (@"compatible presets for songAsset: %@",
       [AVAssetExportSession exportPresetsCompatibleWithAsset:songAsset]);



AVAssetExportSession *exporter = [[AVAssetExportSession alloc]
                                  initWithAsset: songAsset
                                  presetName: AVAssetExportPresetAppleM4A];
NSLog (@"created exporter. supportedFileTypes: %@", exporter.supportedFileTypes);
[self handlePlayPauseDefault:0];
exporter.outputFileType = @"com.apple.m4a-audio";
NSString *exportFile = [myDocumentsDirectory() stringByAppendingPathComponent: @"exported.m4a"];
myDeleteFile(exportFile);

appDelegate.libraryUrl = [NSURL fileURLWithPath:exportFile];
exporter.outputURL = appDelegate.libraryUrl;    


    [exporter exportAsynchronouslyWithCompletionHandler:^{
    int exportStatus = exporter.status;
    switch (exportStatus) {
        case AVAssetExportSessionStatusFailed: {

            NSError *exportError = exporter.error;
            NSLog (@"AVAssetExportSessionStatusFailed: %@", exportError);

            break;
        }
        case AVAssetExportSessionStatusCompleted: {
            NSLog (@"AVAssetExportSessionStatusCompleted");



            self.navigationController.navigationBar.userInteractionEnabled = YES;

            break;
        }
        case AVAssetExportSessionStatusUnknown: { NSLog (@"AVAssetExportSessionStatusUnknown"); break;}
        case AVAssetExportSessionStatusExporting: { NSLog (@"AVAssetExportSessionStatusExporting"); break;}
        case AVAssetExportSessionStatusCancelled: { NSLog (@"AVAssetExportSessionStatusCancelled"); break;}
        case AVAssetExportSessionStatusWaiting: { NSLog (@"AVAssetExportSessionStatusWaiting"); break;}
        default: { NSLog (@"didn't get export status"); break;}
    }
}];

谁能帮我 ?

4

1 回答 1

0

您可能会导致某种转换 - 这会很慢(不会比实时快多少)。确保您使用的是直通预设 AVAssetExportPresetPassthrough。

于 2012-06-03T13:21:16.483 回答