0

所以据说在 iOS 4 SDK 中你可以编辑和写入用户的 iTunes 库。我可以从我的 iPhone/iPod 库中成功加载 AVAsset,但作为一个快速测试,我试图使用 AVAssetExportSession 立即覆盖同一个文件,但它总是返回我认为是 AVAssetExportSessionStatusFailed 的状态“4 ...它说的文档:


enum {
    AVAssetExportSessionStatusUnknown,
    AVAssetExportSessionStatusExporting,
    AVAssetExportSessionStatusCompleted,
    AVAssetExportSessionStatusFailed,
    AVAssetExportSessionStatusCancelled,
    AVAssetExportSessionStatusWaiting
};

但在 AVAssetExportSession.h 中它说:


enum {
    AVAssetExportSessionStatusUnknown,
    AVAssetExportSessionStatusWaiting,
    AVAssetExportSessionStatusExporting,
    AVAssetExportSessionStatusCompleted,
    AVAssetExportSessionStatusFailed,
    AVAssetExportSessionStatusCancelled
};
typedef NSInteger AVAssetExportSessionStatus;

这是我正在使用的代码:



// before this, i'm using mpmediapicker to pick an m4a file i synched with my itunes library 

NSURL *assetUrl = [[self.userMediaItemCollection.items objectAtIndex: 0] valueForProperty: MPMediaItemPropertyAssetURL];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL: assetUrl options: nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset: asset presetName: AVAssetExportPresetAppleM4A];
exportSession.outputURL = asset.URL;
exportSession.outputFileType = AVFileTypeAppleM4A;

NSLog(@"output filetype: %@", exportSession.outputFileType);
// prints "com.apple.m4a-audio"

[exportSession exportAsynchronouslyWithCompletionHandler: ^(void) {
    NSLog(@"status: %i for %@", exportSession.status, exportSession.outputURL);
    // prints "status: 4 for ipod-library://item/item.m4a?id=3631988601206299774"
}];

[exportSession release];

所以无论哪种方式......我猜它是“失败”或“取消”。之前有没有其他人成功写入媒体库?

谢谢!

4

2 回答 2

2

您不能写入 iTunes 库,现在只能从中读取。

于 2010-08-22T20:01:06.943 回答
0
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSParameterAssert(library);
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:[NSURL     fileURLWithPath:movieFileName]]) {
   [library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:movieFileName]     completionBlock:^(NSURL *assetURL, NSError *error){}];
}
[library release];
于 2011-06-29T21:42:06.353 回答