如何使用 AVAssetExportSession 覆盖 iPhone/iPod 库中的歌曲?

发布于 2024-09-15 09:31:57 字数 1805 浏览 4 评论 0原文

所以据说在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南街九尾狐 2024-09-22 09:31:57

您无法写入 itunes 库,现在只能从中读取。

you cannot write to itunes library, only read from it now.

一张白纸 2024-09-22 09:31:57
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];
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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文