使用 AssetsLibrary 框架 iPhone 访问库中的视频?
我正在尝试在以下代码的帮助下使用 AssetsLibrary Framework 访问 iPhone 库中的视频...但是当我运行应用程序时,代码不起作用...数组资产仍然为空?我做错了什么?
顺便说一句,我的 iPhone 是 3G 升级到 iPhone 4.1。(但资产框架没有给出任何错误)
NSMutableArray *assets = [[NSMutableArray alloc]init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];
void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != NULL) {
NSLog(@"See Asset: %@", result);
[assets addObject:result];
}
};
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {NSLog(@"dont See Asset: ");
[group enumerateAssetsUsingBlock:assetEnumerator];
}
};
assets = [[NSMutableArray alloc] init];
library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:assetGroupEnumerator
failureBlock: ^(NSError *error) {
NSLog(@"Failure");
}];
I am trying to access videos in iPhone library using AssetsLibrary Framework with the help of following code...but when I run the application the code is not working...the array assets is still empty? What am I doing wrong?
by the way my iPhone is a 3G upgraded to iPhone 4.1.(but assets framework is not giving any error)
NSMutableArray *assets = [[NSMutableArray alloc]init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];
void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != NULL) {
NSLog(@"See Asset: %@", result);
[assets addObject:result];
}
};
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {NSLog(@"dont See Asset: ");
[group enumerateAssetsUsingBlock:assetEnumerator];
}
};
assets = [[NSMutableArray alloc] init];
library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:assetGroupEnumerator
failureBlock: ^(NSError *error) {
NSLog(@"Failure");
}];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
双重初始化:
Double Init:
我正在使用 ELC 图像选择器控制器,它已经在使用 ALAssetsGroupAll,但仍然没有显示任何视频。
我通过添加资产过滤器解决了这个问题。您可以限制为视频、照片或两者。我猜只有照片是默认设置。如果上述失败,请考虑以下行:
I am using ELC Image Picker Controller, and it's already using ALAssetsGroupAll and still not showing any videos.
I solved this by adding an asset filter. You can limit to videos, photos or both. I guess photos-only was the default. Please consider the following line if the above fails:
4.1 升级似乎“破坏”了一些图像选择器示例,请观察以下几行,这些行在您发布的代码之后运行:
这在我的 4.1 iPhone 和模拟器上都提供了零资产。然而,更改 groupTypes 会有所帮助,因此设置
后您应该会开始看到一些资产。
the 4.1 upgrade seems to have 'broken' some of the image picker examples, observe the following lines, which run after the code you have posted:
This gives zero assets both on my 4.1 iPhone and simulator. However changing the groupTypes helps, so set
and you should start seeing some assets.
我在 Xcode 4.1、IOS 5 中执行此操作:
它对我有用。
I did this in Xcode 4.1, IOS 5:
It worked for me.