如何使用 AVAssetExportSession 覆盖 iPhone/iPod 库中的歌曲?
所以据说在 iOS 4 SDK 中你可以编辑并写入用户的 iTunes 库。我可以从 iPhone/iPod 库成功加载 AVAsset,但作为快速测试,我尝试使用 AVAssetExportSession 立即覆盖同一文件,但它总是返回状态“4”,我认为 是 AVAssetExportSessionStatusFailed...在文档中它说:
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];
所以无论哪种方式...我猜它是“失败”或“取消”。以前有其他人成功写入媒体库吗?
谢谢!
So supposedly in the iOS 4 SDK you can edit and write to the user's iTunes library. I can successfully load an AVAsset from my iPhone/iPod library, but as a quick test I'm trying to just overwrite the same file right away using AVAssetExportSession but it's always returning the status "4" which I THINK is AVAssetExportSessionStatusFailed... In the documentation it says:
enum {
AVAssetExportSessionStatusUnknown,
AVAssetExportSessionStatusExporting,
AVAssetExportSessionStatusCompleted,
AVAssetExportSessionStatusFailed,
AVAssetExportSessionStatusCancelled,
AVAssetExportSessionStatusWaiting
};
but in AVAssetExportSession.h it says:
enum {
AVAssetExportSessionStatusUnknown,
AVAssetExportSessionStatusWaiting,
AVAssetExportSessionStatusExporting,
AVAssetExportSessionStatusCompleted,
AVAssetExportSessionStatusFailed,
AVAssetExportSessionStatusCancelled
};
typedef NSInteger AVAssetExportSessionStatus;
Here's the code I'm using:
// 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];
So either way... I guess it's "failed" or "cancelled." Has anyone else successfully written to the media library before?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法写入 itunes 库,现在只能从中读取。
you cannot write to itunes library, only read from it now.