i wanna get all videos list from ipad video library and show in table view controller and then play inside the app. is it possible?
This Developer.apple documentation explains how to use an image picker controller and delegate for browsing and choosing saved pictures and movies. If the standard media browsing UI does not suit your needs, you can create a fully custom solution with UIKit and the Assets Library framework
Media types To specify whether the image picker controller displays saved movies, still images, or both, set the mediaTypes property to an array containing identifiers for the desired types. The valid values for elements of the array are kUTTypeImage and kUTTypeMovie.
Presenting the media browser interface full screen on iPhone or iPod touch
-(BOOL) startMediaBrowserFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
// Displays saved pictures and movies, if both are available, from the
// Camera Roll album.
mediaUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
mediaUI.allowsEditing = NO;
mediaUI.delegate = delegate;
[controller presentModalViewController: mediaUI animated: YES];
return YES;
}
- (IBAction) showSavedMediaBrowser {
[self startMediaBrowserFromViewController: self
usingDelegate: self];
}
Delegate method for picked media
- (void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info {
}
Yes it is possible.
You can get all video's asset urls using the following code:
NSMutableArray* assetURLs = [[NSMutableArray alloc] init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop)
{
if(result != nil)
{
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo])
{
[assetURLs addObject:[result valueForProperty:ALAssetPropertyURLs]];
NSLog(#"result is:%#",result);
NSURL *url= (NSURL*) [[result defaultRepresentation]url];
[library assetForURL:url
resultBlock:^(ALAsset *asset)
{
// do stuff here
}
failureBlock:^(NSError *error){ NSLog(#"test:Fail"); } ];
}
}
};
You can use the asset url to get that video.
After that create the thumbnail of the video and display it in the tableView.
Also you can play the video using the asset url:
Asset url will look like: assets-library://asset/asset.m4v?id=100&ext=m4v
NSString *urlAddress = #"assets-library://asset/asset.m4v?id=100&ext=m4v";
NSURL *movieURL= [NSURL URLWithString:urlAddress];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL: movieURL];
For more refer:
AssetsLibrary
MPMoviePlayerController
Related
Hi I am getting a problem in load images from the gallery to UIImageView in Xcode 5.
When I am trying to get images from the Gallery in UIImage it will generate exceptional error in my screen.
You can use following method to load image from gallery.
You have to call methodToCallPhotos when you click on gallery button.
-(void)methodToCallPhotos
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
}
After this when you select any image from the gallery. It calls delegate method like below
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
imageView.image = image;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
First of all check if your app is granted permission to access Photo gallery.
Have a look at the documentation for ALAssetsLibrary here. To access all photos and videos you need to enumerate all groups (albums) in the photo library and then enumerate all photos and images in each group.
ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
[al enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if (asset)
{
.. do something with the asset
}
}
}
failureBlock:^(NSError *error)
{
.. handle error
}
];
can we get albums and its images from iphone camera roll? I want to show iphone camera roll albums names in my application
Can this be done using AlAssetLibrary is yes how?
To open iPhone photo library use like that:
-(IBAction)pickphoto:(id)sender
{
[self startMediaBrowserFromViewController: self usingDelegate: self];
}
- (BOOL) startMediaBrowserFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate{
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
mediaUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie,kUTTypeImage, nil];
mediaUI.allowsEditing = YES;
mediaUI.delegate = delegate;
[controller presentModalViewController: mediaUI animated: YES];
return YES;
}
- (void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info
{
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
thumbnail = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
[self dismissModalViewControllerAnimated:YES];
}
Hope it helps you.
I am using UIImagePickerController to record a video with the sourceType set to UIImagePickerControllerSourceTypeCamera.
I have set allowsEditing to true.
After capturing video I edit the video using the trimming interface and press "Use", I only get back the original recording not the trimmed version. What am I doing wrong?
I am using iOS 5.
-(void)shootvideo {
imagePicker = [[UIImagePickerController alloc] init];
[imagePicker.view addSubview:test];
[imagePicker.view addSubview:test2];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
imagePicker.showsCameraControls = YES;
imagePicker.navigationBarHidden = NO;
imagePicker.toolbarHidden = NO;
imagePicker.wantsFullScreenLayout = YES;
imagePicker.allowsEditing=YES;
[self presentModalViewController:imagePicker animated:YES];
}
-(void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info
{
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0)
== kCFCompareEqualTo)
{
NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
//NSLog(#"%#",moviePath);
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
}
[self dismissModalViewControllerAnimated:YES];
}
I want to use that trimmed video for further processing according to my application.
Where I am going wrong?
Is there any other way to achieve this task?
allowsEditing : A Boolean value indicating whether the user is allowed to edit a selected still image or movie.
#property (nonatomic) BOOL allowsEditing
Discussion
If you allow the user to edit still images or movies, the delegate may receive a dictionary with information about the edits that were made. The protocol for the delegate is described in UIImagePickerControllerDelegate Protocol Reference.
I Think this will be helpful.
you need to grab the info[UIImagePickerControllerEditedImage] from the - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
I believe.
I want to open new view controller just after pressing stop video capturing button.
I am using this code but i am unable to do this.
-(void)shootvideo
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[self presentModalViewController:imagePicker animated:YES];
}
-(void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info
{
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0)
== kCFCompareEqualTo)
{
NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSURL *videoUrl=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
}
[self dismissModalViewControllerAnimated:YES];
// nextviewcontroller *test=[[nextviewcontroller alloc]init];
//[self.navigationController pushViewController:test animated:YES];
}
}
Just after pressing the stop capturing video button I want to navigate to another view.
You have presented the image picker by presentModalViewcontroller so you cant call [self.navigationController pushViewController:test animated:YES]; on image picker. You have two options one is simple
1) Instead of calling [self dismissModalViewControllerAnimated:YES]; on image picker, just call
nextviewcontroller *test=[[nextviewcontroller alloc]init];
[self presentModalViewController:nextviewcontroller animated:YES];
2) Use delegates to call new view controller.
its possible if you use performSelector with Delay time 0.2 near about ....here just call the method and its work fine
and in method you can push your nextViewController....
hope this help you...
:)
I have a UIPickerController to select videos in my App and it is crashing when selecting videos using the picker. When I feed the MPMoviePlayerController with the URL directly it works fine, but when the URL comes from the UIPickerController, it loads the movie correctly but crashes when the thumbnails are being created.
I have dumped the URL to the console, just after the file is selected and this is what I see
file://localhost/private/var/mobile/Applications/FA667F85-B009-46FA-A0B9-A7345A072651/tmp//trim.Ir0gqx.MOV
first question: why is the double bar before the file name?
second question: why the file name comes with a trim prefix if I have editing NO on the picker?
this is the picker code:
- (void) selectMovie:(id) sender {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
NSArray *mediaTypesAllowed = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
picker.delegate = self;
picker.allowsEditing = NO;
picker.videoQuality = UIImagePickerControllerQualityTypeHigh; // I've added this trying to make it stop compressing the video, but it won't... any clues?
UIPopoverController *aPopover =
[[UIPopoverController alloc] initWithContentViewController:picker];
aPopover.delegate = self;
CGRect myRect = [sender frame];
[aPopover presentPopoverFromRect:myRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ( [ mediaType isEqualToString:#"public.movie" ]){
movieURL = [info objectForKey:UIImagePickerControllerMediaURL];
}
NSLog(#"%#", movieURL);
[self loadMovie:movieURL];
}
My thought is that your app does not have permission to generate thumbnails in the location where the movie is stored. Try copying the movie file out of the photo albums and into your documents directory:
NSFileManager *fm = [NSFileManager defaultManager];
[fm moveItemAtURL:fromURL toURL:toURL error:&error];
Assuming you have a toURL pointing to a filename in your docs directory.
I only know about the first one, because you need to feed to MPMoviePlayerController a url, a url has to start with a scheme, http://, smtp://, kind of that. file:// is also a scheme for file url