我尝试从相机胶卷中检索视频的所有 URL,并将NSURL
对象保存到NSMutableArray
. 正如您在代码中看到的那样,我还在控制台中打印 URL 以查看它们是否不为空/nil。因此,我使用以下方法:
- (void)buildCameraRollLibrary{
camerRollList = [[NSMutableArray alloc] init];
library = [[ALAssetsLibrary alloc] init];
UIImage *viewImage;
[library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation:(ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
NSLog(@"error");
} else {
NSLog(@"url %@", assetURL);
}
}];
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop){
if (group != NULL) {
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop){
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {
//NSLog(@"asset: %@", result);
ALAssetRepresentation* defaultRepresentation = [result defaultRepresentation];
NSURL *url = [defaultRepresentation url];
NSLog(@"%@",url);
[camerRollList addObject:url];
}
}];
}
}
failureBlock:^(NSError *error){
NSLog(@"failure"); }];
}
我的问题是,我可以在控制台中看到我所有视频的正确 URL,但是如果我将它们添加到我的cameraRollList
NSMutableArray
中,那么这个数组是空的。
有没有人建议我如何解决这个问题?有关信息,我想使用此 URL 播放AVPlayer
.
先感谢您!
附上你可以看到我的控制台的输出:
2013-11-08 22:09:41.629 SwiPlayer[621:60b] assets-library://asset/asset.MOV?id=5D39F2FA-E161-450C-AC6F-27348754112A&ext=MOV
2013-11-08 22:09:41.648 SwiPlayer[621:60b] assets-library://asset/asset.MOV?id=DD7925FA-9F06-403D-ACBA-13A9C7B6E1AF&ext=MOV
2013-11-08 22:09:41.664 SwiPlayer[621:60b] assets-library://asset/asset.mov?id=B277D0E9-E6CA-44FA-9365-72E3BCDA2156&ext=mov
2013-11-08 22:09:41.667 SwiPlayer[621:60b] assets-library://asset/asset.mp4?id=7929B692-EEA3-4918-B63F-DB77B13A8499&ext=mp4
2013-11-08 22:09:41.669 SwiPlayer[621:60b] assets-library://asset/asset.MOV?id=32B60AA6-D46D-40B3-A97F-6980A999D048&ext=MOV
2013-11-08 22:09:41.686 SwiPlayer[621:60b] assets-library://asset/asset.MOV?id=45FCEC33-A158-4794-B9DB-C70E8A828F35&ext=MOV
2013-11-08 22:09:41.694 SwiPlayer[621:60b] assets-library://asset/asset.MOV?id=3157C207-7649-4E0F-A8E2-943C3C95298F&ext=MOV
2013-11-08 22:09:41.697 SwiPlayer[621:60b] assets-library://asset/asset.MOV?id=6B043E7C-4399-4376-8B1B-51DDF3DD79DD&ext=MOV
2013-11-08 22:09:41.762 SwiPlayer[621:60b] url (null)