【发布时间】:2014-01-15 03:17:34
【问题描述】:
我正在制作一个 iOS 应用程序,用户可以在其中录制视频,一旦完成录制,他就可以将该视频发送到服务器。 到现在为止还挺好! 但是找到录制的视频是一件很头疼的事!如何找到录制视频的正确 URL? 在我的测试过程中,我在 Supporting Files 文件夹中保存了一个视频,我的代码如下
NSString *url = [[NSBundle mainBundle] pathForResource:@"trailer_iphone" ofType:@".m4v"];
NSData *data = [NSData dataWithContentsOfFile:url];
那么我可以做些什么来替换照片库中的那个 URL?
在 Apple Developer 网站上显示我们可以使用 AVAsset 来访问照片库。所以我复制到我的代码中,我正在尝试解决这个问题!
//Copied from Apple website
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Within the group enumeration block, filter to enumerate just videos.
[group setAssetsFilter:[ALAssetsFilter allVideos]];
// For this example, we're only interested in the first item.
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0]
options:0
usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
NSURL *url = [representation url];
AVAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
// Do something interesting with the AV asset.
//My last code
//NSString *url = [[NSBundle mainBundle] pathForResource:@"trailer_iphone" ofType:@".m4v"];
NSData *data = [NSData dataWithContentsOfURL:url];
【问题讨论】:
标签: ios video photo-gallery assets