views:

104

answers:

4

I am writing an application that stores the movies in the photo roll into the local documents folder for the app. I can play remote movies using the MPMoviePlayer, however trying to play a movie stored in the documents folder for the app always returns MPMovieLoadStateUnknown.

The notifications are all getting sent and received from the default notification center (MPMoviePlayerLoadStateDidChangeNotification, MPMoviePlayerPlaybackDidFinishNotification). An alert box shows up shortly after getting the loadStateUnknown message in the console, saying that the movie could not be played and the app then receives the movie playback completed notification.

I think that it may be a case that the filename (MPMoviePlayer can only take a URL as the asset location) cannot be found. Has anyone dealt with this issue or similar?

A: 

have you tried converting the local file path to a url

[NSURL URLWithString: [NSString stringWithFormat:@"file:/%@//",filePath]];

if there are spaces in you file path, you will have to convert them prior to creating the URL

filePath = [filePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
filePath = [filePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
Aaron Saunders
A: 

The Core Data template converts a file path to a URL like this:

NSURL *storeUrl = [NSURL fileURLWithPath:whatever];

That seems to do all of the correct space escaping and stuff because I'm using this to load a file with a space in the path.

Nimrod
Doing this provides the same result as my orignal question. If I do [NSData dataWithContentsOfURL:storeUrl] and NSLog that out I get a giant list of HEX numbers, so I know that is finding the file, or the data would be nil. Does the file for MPMoviePlayer require an extenstion?
Kyle
Did you test the movie to make sure it plays when dragged into iTunes and synced?
Nimrod
The movie was created in PhotoBooth and emailed to the ipad. The movie was saved as iPhone compatible with Quicktime and plays from the photo roll, and on the Mac.
Kyle
A: 

Hi, I am not sure if this will help you. In this tutorial there are some code lines which probably will bring you on the right path:

    // Unless state is unknown, start playback
if ([mp loadState] != MPMovieLoadStateUnknown)
...

You will find this snippet in following method:

- (void) moviePlayerLoadStateChanged:(NSNotification*)notification 

here is the link to the tutorial: Tutorial

Hopefully this will help you...

Micko
+1  A: 

Given that none of the other answers seem to resolve the problem, I'm inclined to think that the problem might be with the Documents file path you are producing.

You should be using the following method to generate the path to the application's documents folder:

NSString *userDocumentsPath = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if ([paths count] > 0) 
{
     userDocumentsPath = [paths objectAtIndex:0];
}
Alan Rogers
Think I tried everything but this. Can't thank you enough!
Kyle
Glad I could help! :)
Alan Rogers