MPMediaPickerController for selecting video files
I want to enable the user to select a video file from the 开发者_JAVA技巧on-device iPod library (so that I can play it in my own app). Is that possible? I was thinking on using MPMediaPickerController but I am not sure if it is able to select video files or just audio files.
Any help will be greatly appreciated.
Thanks,
It seems this is possible in iOS 5 with MPMediaPickerController, which now allows setting these types:
// video media types
MPMediaTypeMovie = 1 << 8,
MPMediaTypeTVShow = 1 << 9,
MPMediaTypeVideoPodcast = 1 << 10,
MPMediaTypeMusicVideo = 1 << 11,
MPMediaTypeVideoITunesU = 1 << 12,
MPMediaTypeAnyVideo = 0xff00,
Which are os 5 only.
Once you have your collection of items, you'll need to access the url:
MPMediaItem * item = ....
NSString *url = [item valueForProperty:@"MPMediaItemPropertyAssetURL"];
And this url can only be used with AV Foundation, so use AVPlayer, not MPMoviePlayerController.
From the docs:
MPMediaItemPropertyAssetURL
A URL pointing to the media item, from which an AVAsset object (or other
URL-based AV Foundation object) can be created, with any options as desired.
Value is an NSURL object.
The URL has the custom scheme of ipod-library. For example, a URL might look
like this:
ipod-library://item/item.m4a?id=12345
Usage of the URL outside of the AV Foundation framework is not supported.
Available in iOS 4.0 and later.
The picker has a property called mediaTypes
, this is an enumeration declared here, like this:
enum {
// audio media types
MPMediaTypeMusic = 1 << 0,
MPMediaTypePodcast = 1 << 1,
MPMediaTypeAudioBook = 1 << 2,
MPMediaTypeAnyAudio = 0x00ff,
// generic media type
MPMediaTypeAny = ~0
};
As you can see nothing indicates beeing something non-audio, except MPMediaTypeAny
but the docs say
MPMediaTypeAny If set, the media item contains an unspecified type of audio.
That means only audio, sorry. :(
Do it like this:
IImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
// UIImagePickerControllerSourceTypeSavedPhotosAlbum;// UIImagePickerControllerSourceTypePhotoLibrary
imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:imagePicker.sourceType];
imagePicker.allowsEditing = NO;
精彩评论