MPMoviePlayer loading and playing saved in application documents

I am writing an application that stores movies in a photo brochure in a folder of local documents for the application. I can play deleted movies using MPMoviePlayer, however, trying to play a movie stored in the document folder, the application always returns MPMovieLoadStateUnknown .

All notifications are sent and received from the default notification center ( MPMoviePlayerLoadStateDidChangeNotification , MPMoviePlayerPlaybackDidFinishNotification ). A warning window will appear shortly after receiving a loadStateUnknown message in the console saying that the movie cannot be played, and the application then receives a notification that the movie has finished playing.

I think this may be the case when the file name (MPMoviePlayer can only accept the URL as the location of the asset) cannot be found. Has anyone dealt with this problem or the like?

+6
objective-c iphone ipad mpmovieplayercontroller
source share
4 answers

Given that none of the other answers seem to solve the problem, I am inclined to think that the problem may be that you are creating the path to the document files.

To create the path to the application document folder, you must use the following method:

 NSString *userDocumentsPath = nil; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); if ([paths count] > 0) { userDocumentsPath = [paths objectAtIndex:0]; } 
+1
source share

You tried to convert the local file path to the url

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

If there are spaces in your file path, you will need to convert them before creating the URL

 filePath = [filePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"]; filePath = [filePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; 
0
source share

The master data template translates a path to a URL like this:

 NSURL *storeUrl = [NSURL fileURLWithPath:whatever]; 

It seems like all the correct deletion of space and stuff, because I use this to upload a file with a space in the path.

0
source share

I'm not sure if this will help you. There are some lines of code in this tutorial that will probably lead you to the correct path:

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

You will find this snippet in the following way:

 - (void) moviePlayerLoadStateChanged:(NSNotification*)notification 

here is the link to the tutorial: Tutorial

Hope this helps you ...

0
source share

All Articles