【问题标题】:AVAssetExportSession not working in ios5AVAssetExportSession 在 ios5 中不起作用
【发布时间】:2011-12-22 13:44:36
【问题描述】:

在我的应用程序中,我使用 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];
}

【问题讨论】:

    标签: iphone objective-c ios5 avfoundation avassetexportsession


    【解决方案1】:

    我为自己整理了答案,并希望与遇到相同问题的其他人分享。

    问题是由于某种原因AVAssetExportPresetPassthrough 在 ios5 中无法正常工作。用AVAssetExportPresetAppleM4A 代替它解决了这个问题。
    但是现在导出需要更长的时间。

    【讨论】:

    • 有人知道为什么 AVAssetExportPresetPassthrough 不起作用吗?使用 AVAssetExportPresetAppleM4A 导出时会导致大量时间延迟。
    【解决方案2】:

    也许一种解决方法是直接使用 AVAssetWriter 而不是使用 AVAssetExportSession。请在http://bugreport.apple.com 提交一个错误,以便它在iOS5 的下一个版本中得到修复。 (我自己提交了一份,但越多越好。)

    【讨论】:

    • 我还提交了错误报告。我想知道需要这个的应用程序(例如:DJ 应用程序)如何应对 iOS5.1
    【解决方案3】:

    作为一种解决方法,我发现使用 .mov 作为文件扩展名,然后将其重命名为 mp3 似乎可行。我不需要为 m4a 文件执行此操作。

    【讨论】:

      猜你喜欢
      • 2011-12-12
      • 2011-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多