Search code examples
iosvideomovie

iOS Any way to retrieve all videos?


I have to get list of videos from device. I know how to get videos from camera roll with help of UIImagePickerController. But, using UIImagePickerController, I can't get videos that are shown in the "Videos" application (standard iOS application).

What should I use? Is any standard(or GitHub) controller for my purposes?


Solution

  • Okey, finally with help of Lyndsey Scott I've answered my own question:

    1. There no standard control to get video from media library (UIImagePickerController get videos only from camera roll or albums).
    2. So, I use next code to get and enum Videos:

      MPMediaQuery *videoQuery = [[MPMediaQuery alloc] init];
      
      NSMutableArray *items = [NSMutableArray arrayWithCapacity:0];
      NSArray *mediaItems = [videoQuery items];
      
      // Maybe do something with title and URL
      for (MPMediaItem *mediaItem in mediaItems) {
          NSURL *URL = (NSURL*)[mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
          if (URL) {
              NSString *title = (NSString*)[mediaItem valueForProperty:MPMediaItemPropertyTitle];
          }
      }
      

    and then I've created my own ViewController with fetched list of movies.

    P.S. If I've missed something or have posted wrong answer - please correct me