Мое приложение для iphone может сохранять фотографии и видео в Фотопленке, и я также смог получить доступ к элементам в фотопленке.
Отображать фотографии из фотопленки было легко, я сделал это с помощью ALAssetsLibraryи это прекрасно показывает в UIImage.Я тоже могу получить доступ к видео и попытался отобразить видео с помощью MPMoviePlayerController.
Вот мой код:
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:^(ALAssetsGroup *group, BOOL *stop){
// Within the group enumeration block, filter to enumerate just videos.
[group setAssetsFilter:[ALAssetsFilter allVideos]];
// Chooses the video at the last index
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:([group numberOfAssets]-1)]
options:0
usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop){
if (alAsset){
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: [representation url]];
[moviePlayer.view setFrame:CGRectMake(20, 20, 200, 300)];
[self.view addSubview: moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];
}
}
];
}
failureBlock: ^(NSError *error){
// handle error
NSLog(@"No groups");
}
];
Я вижу только черную рамку, но не видео.
Кто-нибудь может мне помочь?
Спасибо.