簡體   English   中英

AVAssetExportSession在iOS5中不起作用

[英]AVAssetExportSession not working in ios5

在我的應用程序中,我使用AVAssetExportSession合並了兩個音頻文件,在早期的ios版本中可以正常工作,但是在ios5設備中無法正常工作。 我得到的是一個錯誤

AVAssetExportSessionStatusFailed: Error Domain=AVFoundationErrorDomain Code=-11820 "Cannot Complete Export" UserInfo=0x1df1c0 {NSLocalizedRecoverySuggestion=Try exporting again., NSLocalizedDescription=Cannot Complete Export}

下面給出了我用於導出的代碼

有人遇到過同樣的問題嗎? 請提供您寶貴的建議。 我迫切需要解決此問題。

//Export function to export the combined audios as one.
-(void)exportAudioFile:(AVComposition*)combinedComposition
{
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:combinedComposition
                                                                           presetName:AVAssetExportPresetPassthrough];
    NSArray *presets =[AVAssetExportSession exportPresetsCompatibleWithAsset:combinedComposition];
    NSLog(@"presets======%@",presets);
    NSLog (@"can export: %@", exportSession.supportedFileTypes);
    NSArray *dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectoryPath = [dirs objectAtIndex:0];
    exportPath = [documentsDirectoryPath stringByAppendingPathComponent:@"CombinedNew.m4a"];
    [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
    exportURL = [NSURL fileURLWithPath:exportPath];
    exportSession.outputURL = exportURL;
    exportSession.outputFileType = @"com.apple.m4a-audio";
    exportSession.shouldOptimizeForNetworkUse = YES;
    [exportSession exportAsynchronouslyWithCompletionHandler:^{
        NSLog (@"i is in your block, exportin. status is %d",
               exportSession.status);
        switch (exportSession.status) 
        {
            case AVAssetExportSessionStatusFailed: 
            {
                // log error to text view
                NSError *exportError = exportSession.error;
                DEBUG_LOG(@"AVAssetExportSessionStatusFailed: %@", exportError);
                [self enableUI];
                break;
            }
            case AVAssetExportSessionStatusCompleted: 
            {
                DEBUG_LOG(@"AVAssetExportSessionStatusCompleted");
                DEBUG_LOG(@"Completed export");
                exportSuccess = YES;
                if (recorderFilePath) 
                {
                    NSError *finalurlError;
                    [[NSFileManager defaultManager]removeItemAtPath:recorderFilePath  error:&finalurlError];
                    finalurlError = nil;
                    [[NSFileManager defaultManager]copyItemAtPath:[exportURL path] toPath:recorderFilePath error:&finalurlError];
                }
                isExported = YES;
                fileUrl = [NSURL fileURLWithPath:recorderFilePath];  
                [self performSelectorInBackground:@selector(updatePlayerForUrl:) withObject:fileUrl];
                break;
            }
            case AVAssetExportSessionStatusUnknown: 
            {   
                DEBUG_LOG(@"AVAssetExportSessionStatusUnknown");                 
                break;
            }
            case AVAssetExportSessionStatusExporting: 
            { 
                DEBUG_LOG(@"AVAssetExportSessionStatusExporting");                 
                break;
            }
            case AVAssetExportSessionStatusCancelled: 
            { 
                DEBUG_LOG(@"AVAssetExportSessionStatusCancelled");
                break;
            }
            case AVAssetExportSessionStatusWaiting: 
            { 
                DEBUG_LOG(@"AVAssetExportSessionStatusWaiting");                 
                break;
            }
            default: 
            { 
                DEBUG_LOG(@"didn't get export status");                
                break;
            }

        };
    }];
    [exportSession release];
}

我為自己整理了答案,並希望與遇到相同問題的其他人分享。

問題是由於某種原因AVAssetExportPresetPassthrough在ios5中無法正常工作。 AVAssetExportPresetAppleM4A替代它可以解決此問題。
但是現在出口需要更長的時間。

可能的解決方法是直接使用AVAssetWriter而不使用AVAssetExportSession。 請拜托,請在http://bugreport.apple.com上提交錯誤,以便在下一版iOS5中修復該錯誤。 (我提交了自己的一份,但越多越好。)

解決方法是,我發現使用.mov作為文件擴展名,然后將其重命名為mp3似乎可行。 我不需要對m4a文件執行此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM