1

I'm using this to play a local .mov file

 NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:@"MOVIE" ofType:@"mov"]];

 moviePlayer =
 [[MPMoviePlayerController alloc]
 initWithContentURL:url];

 [moviePlayer setControlStyle:MPMovieControlStyleNone];

 [[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector( moviePlayBackDidFinish:)
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:moviePlayer];
 [moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
 [moviePlayer setFullscreen:FALSE];

 //---play partial screen---
 moviePlayer.view.frame = CGRectMake(0, 0, 320, 240);
moviePlayer.shouldAutoplay = YES;
 [self.view addSubview:moviePlayer.view];
[moviePlayer play];

I'd like to pre-load a video from a url and save it to the drive, so that there is no network lag while it is playing. How can I save the file from the url and then load it into the mpmovieplayer.

It seems like it must be something like this...

NSString *stringURL = @"url to file";
NSURL  *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];

but I don't know how to initialize it with the data if this is the case.

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
Cherr Skees
  • 1,508
  • 2
  • 21
  • 37

1 Answers1

0

You can use NSURLConnection to download the contents of a URL, and it's up to you to decide where/how you want that stored. Then load the URL of the local file into your movie player.

It seems inadvisable to me to try and keep the whole video in memory; it may simply be too big for that!

That said, do you really need to do this? How is letting MPMoviePlayerController handle this failing you at the moment?

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
  • They are short movie clips ~6-10sec. I want the user to answer questions based on them and be timed on their answers. That's why I'm worried about buffering delays. I have MPMoviePlayer working fine for locally stored files. I just want the time to not be delayed based on the network connection. – Cherr Skees Apr 14 '13 at 20:40
  • Fair enough. You want to download the videos and store them locally then. Trying to keep multiple videos, however short, in-memory is asking for trouble. – Mike Abdullah Apr 16 '13 at 13:11