gpt4 book ai didi

iphone - 使用exportAsynchronouslyWithCompletionHandler

转载 作者:行者123 更新时间:2023-12-03 18:54:39 25 4
gpt4 key购买 nike

我尝试从 iPod 库导出音频文件。我想用这个 iPod-Library 文件创建一个新文件。在《AV Foundation 编程指南》的“读取和写入 Assets ”一章中,有一个小示例。但是这段代码对我不起作用。发生 4 个错误

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}

我的代码

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];
}

nslog 消息

-[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}

我该如何修复这四个错误。我是否需要导出 AVAssetReader 和 AVAssetWriter?

最佳答案

我从 AVAssetExportSession 得到了相同的结果,完全无用的 NSError 试图告诉你的是,你要导出的路径不完全存在。您需要确保使用 NSFileManager 创建了要放置文件的目录的路径。

关于iphone - 使用exportAsynchronouslyWithCompletionHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5470640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com