5

I try to export an audio file from the iPod-Library. I want to create with this iPod-Library file an new file. In the AV Foundation Programming Guide in chapter Reading and Writing Assets there is a little example. However this code doesn't work for me. 4 errors happens

Export Status 4 Error Domain=AVFoundationErrorDomain 
Code=-11800 "The operation could not be completed" 
UserInfo=0x1edfa0 {NSLocalizedFailureReason=An unknown error occurred (-12124), 
NSUnderlyingError=0x1ebdc0 "The operation couldn’t be completed. (OSStatus error -12124.)", 
NSLocalizedDescription=The operation could not be completed}

My code

AVURLAsset *objAvUrlAsset = [[AVURLAsset alloc] initWithURL:[tempArray objectAtIndex:0]  options:nil];

NSLog(@"%s objAvUrlAsset %@", __FUNCTION__, objAvUrlAsset);

NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:objAvUrlAsset];

NSLog(@"%s compatiblePresets %@", __FUNCTION__, compatiblePresets);

if ([compatiblePresets containsObject:AVAssetExportPresetAppleM4A]) {


    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
                                           initWithAsset:objAvUrlAsset presetName:AVAssetExportPresetAppleM4A];

    NSString * exportPath = [NSString stringWithFormat:@"testTrack1.M4A"];
    NSURL *exportURL = [NSURL fileURLWithPath:exportPath];

    exportSession.outputURL = exportURL;
    exportSession.outputFileType = AVFileTypeAppleM4A;
    exportSession.shouldOptimizeForNetworkUse = YES;

     NSLog(@"%s export Session %@",__FUNCTION__, exportSession);

    [exportSession exportAsynchronouslyWithCompletionHandler: ^(void) {
        // export completed
        NSLog(@"Export Status %d %@", exportSession.status, exportSession.error);
    }];
    [exportSession release];
}

the nslog message

-[MyLocalMusicLibrary getAllTracks] objAvUrlAsset AVURLAsset: 0x1dd5a0, URL = ipod-library://item/item.mp3?id=-212958261728896866

 -[MyLocalMusicLibrary getAllTracks] compatiblePresets (
AVAssetExportPresetAppleM4A,
AVAssetExportPreset960x540,
AVAssetExportPresetLowQuality,
AVAssetExportPresetMediumQuality,
AVAssetExportPreset640x480,
AVAssetExportPresetHighestQuality,
AVAssetExportPreset1280x720
)

 -[MyLocalMusicLibrary getAllTracks] export Session AVAssetExportSession: 0x1e85c0, 
asset = AVURLAsset: 0x1dd5a0, URL = ipod-library://item/item.mp3?id=-212958261728896866, 
presetName = AVAssetExportPresetAppleM4A, outputFileType = com.apple.m4a-audio

 -[MyLocalMusicLibrary getAllTracks] Export Status 4 Error Domain=AVFoundationErrorDomain 
Code=-11800 "The operation could not be completed" 
UserInfo=0x1edfa0 {NSLocalizedFailureReason=An unknown error occurred (-12124), 
NSUnderlyingError=0x1ebdc0 "The operation couldn’t be completed. (OSStatus error -12124.)", 
NSLocalizedDescription=The operation could not be completed}

How can i fix this four errors. Do i need for this export the AVAssetReader and AVAssetWriter.

4

2 に答える 2

8

から同じ結果が得られましAVAssetExportSessionた。まったく役に立たないNSErrorことを伝えようとしているのは、エクスポート先のパスが完全には存在しないということです。を使用して、ファイルを配置するディレクトリへのパスを作成する必要がありますNSFileManager

于 2011-08-11T15:17:24.207 に答える