MPMediaPickerController用于选择视频文件

时间:2010-03-18 11:49:51

标签: iphone video mpmediapickercontroller

我想让用户从设备上的iPod库中选择一个视频文件(以便我可以在自己的应用程序中播放)。那可能吗? 我正在考虑使用MPMediaPickerController,但我不确定它是否能够选择视频文件或只是音频文件。

非常感谢任何帮助。

谢谢,

3 个答案:

答案 0 :(得分:1)

这似乎可以在带有MPMediaPickerController的iOS 5中实现,现在可以设置这些类型:

  // video media types
  MPMediaTypeMovie        = 1 << 8,
  MPMediaTypeTVShow       = 1 << 9,
  MPMediaTypeVideoPodcast = 1 << 10,
  MPMediaTypeMusicVideo   = 1 << 11,
  MPMediaTypeVideoITunesU = 1 << 12,
  MPMediaTypeAnyVideo     = 0xff00,

仅限os 5。

收集完商品后,您需要访问网址:

MPMediaItem * item = ....
NSString *url = [item valueForProperty:@"MPMediaItemPropertyAssetURL"];

此网址只能与AV Foundation一起使用,因此请使用AVPlayer,而不是MPMoviePlayerController。

来自文档:

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.

答案 1 :(得分:0)

选择器有一个名为mediaTypes的属性,这是一个声明为here的枚举,如下所示:

enum {
   // audio media types
   MPMediaTypeMusic        = 1 << 0,
   MPMediaTypePodcast      = 1 << 1,
   MPMediaTypeAudioBook    = 1 << 2,
   MPMediaTypeAnyAudio     = 0x00ff,

   // generic media type
   MPMediaTypeAny          = ~0
};

正如你所看到的,除了MPMediaTypeAny之外没有任何东西表明是非音频的东西,但文档说

  

MPMediaTypeAny 如果设置,则媒体项目包含未指定的类型   音频。

这意味着只有音频,对不起。 :(

答案 2 :(得分:0)

这样做:

IImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    // UIImagePickerControllerSourceTypeSavedPhotosAlbum;// UIImagePickerControllerSourceTypePhotoLibrary
    imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:imagePicker.sourceType];
    imagePicker.allowsEditing = NO;