Accessing iPhone/iPod video gallery
how I can access the video galley in my iPhone view SDK. What the object I must to use to this that task.
I want to show all videos ( on iPhone/iPod ) in my开发者_开发技巧 app and then upload selected videos on web server.
Thanks.
The starting point is UIImagePickerController
to choose a video, and MPMoviePlayerController
and MPMoviePlayerViewController
for playback.
First, create a UIImagePickerController
On your class, you will need to implement the UIImagePickerControllerDelegate protocol and wire it up to the delegate
property on the picker. You should be able to get the location of the media selected from didFinishPickingMediaWithInfo
once the user has selected something.
// untested
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// this is the file system url of the media
NSURL* videoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
// TODO: read in data at videoUrl and write upload it to your server
}
If you use UIImagePickerController
, be sure to play around with the sourceType
property to access the library instead of the live camera. See UIImagePickerControllerSourceType
for details.
These are your options:
enum {
UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
};
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
NSArray *mediaTypesAllowed = [NSArray arrayWithObjects:@"public.image", @"public.movie", nil];
[imagePickerController setMediaTypes:mediaTypesAllowed];
[self presentModalViewController:imagePickerController animated:YES];
精彩评论