How to show iPhone Video library in UITableview programatically
Use the following code in XCode
-(void)viewDidAppear:(BOOL)animated
{
assetsCollection=[[NSMutableArray alloc] init];
al =[[ALAssetsLibrary alloc] init];
UIImage *viewImage;
[al writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation:(ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {NSLog(@"error");
} else {
NSLog(@"url %@", assetURL);
}];
[al enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{if (group!=NULL)
{
[group setAssetsFilter:[ALAssetsFilter allVideos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if (asset) {
NSLog(@"asset: %@", asset);
[assetsCollection addObject:asset];
}
} ];
}
failureBlock:^(NSError *error)
{
NSLog(@"error enumerating AssetLibrary groups %@\n", error);
}];
if([UIApplication sharedApplication].statusBarHidden)
{
[UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleBlackOpaque;
[UIApplication sharedApplication].statusBarHidden=NO;
}{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil)
{
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}if(tableView.tag==0)
{
ALAsset *asset=[assetsCollection objectAtIndex:indexPath.row];
NSLog(@"Asset Collection : %@",assetsCollection);
NSLog(@"Asset %@",[[asset defaultRepresentation] url]);
[cell.iconView setImage:[UIImage imageWithCGImage:[asset thumbnail]]];
[cell.cellLabel setText:[NSString stringWithFormat:@"Video %d", indexPath.row+1]];[cell.playButton setEnabled:YES];
[cell.playButton setImage:[UIImage imageNamed:@"play"] forState:UIControlStateNormal];
[cell.playButton addTarget:self action:@selector(movieplay:) forControlEvents:UIControlEventTouchUpInside];
[cell.playButton setTag:indexPath.row];}
else
{[cell.cellLabel setText:@"Show Resume"];
}
return cell;
-(void)movieplay:(id)sender
{
UIButton *button=(UIButton*)sender;
ALAsset *asset=[assetsCollection objectAtIndex:button.tag];
delegate.movieURL = [[asset defaultRepresentation] url];
MPMoviePlayerViewController *controller=[[MPMoviePlayerViewController alloc] init];
[self presentMoviePlayerViewControllerAnimated:controller];
}
Comments
Post a Comment