My application requires numerous videos to be downloaded from a server at separate times and I was wondering if there was anyway to download the video data and store it for playing later? I originally downloaded the video data and stored it into NSData (see below) but this cannot be used within MPMoviePlayerController.
NSString *imageURL = [NSString stringWithFormat:@"%@%@",@"http://wildknowledge.co.uk",[mapPoint objectForKey:@"videopath"]];
[mapPoint setObject:[NSData dataWithContentsOfURL:[NSURL URLWithString:[imageURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]] forKey:@"videopath"];
I then thought I may be able to setup the URL for later using the following:
NSString *imageURL = [NSString stringWithFormat:@"%@%@",@"http://wildknowledge.co.uk",[mapPoint objectForKey:@"videopath"]];
NSURL *movieURL = [[NSURL alloc] initFileURLWithPath:imageURL];
[mapPoint setObject:movieURL forKey:@"videopath"];
But obviously NSURL only stores a full url location and not the data at that location, so when it comes to playing the video it has to buffer it first which I do not want.
So can anyone tell me the way I can store the data from the NSURL for later use?
If I were you I would use NSFileHandle to read the chunks of movies and save them directly to file system. This way you never keep the movies in the memory so your app should not crash because you never exceed the available memory.
I used this approach in the app when I had to download a big database (>700MB) and it worked pretty well. However, depending on the movie size, you might want to add a validation mechanism to make sure the transmission was successful, for example md5 checksum.