MPMoviePlayerController does not work with movie in document folder

I have a ViewController that plays a movie. If the movie was downloaded (with an ASI-HTTP request), it takes the local version. Otherwise, it transfers it from the Internet. This is the same movie.

Streaming works very well, but playing a local file does not work. Just a black screen and no controls. The file was uploaded correctly. I checked the md5 checksum.

This is Apple QuickTime Video (.mov) of size 1024x5xx.

player = [[MPMoviePlayerController alloc] init]; [player.view setFrame: self.view.bounds]; if (local) { // DOES not work // SHOULD be [NSURL fileURLWithString:...] [player setContentURL: [NSURL URLWithString: @"/path/to/the/movie.mov"]]; } else { // does work [player setContentURL: [NSURL URLWithString: @"http://mydomain.tld/path/to/the/movie.mov"]]; } [self.view addSubview: player.view]; [player play] 

I tried with MediaSourceType players. But it did not help. Why is this not working? I have no error messages because I am not getting one ... is there any way to get error messages from it?

Decision

I found my mistake.

I used [NSURL URLWithString: @"/the/path/..."] for the local path.

It works with [NSURL fileURLWithPath: @"/the/path/..."]

+1
source share
1 answer

Check the URL of the video file. This line returns the path to the Documents directory.

 NSString* docPath = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 

Your path is not linked to a document catalog

 [player setContentURL: [NSURL URLWithString: @"/path/to/the/movie.mov"]]; 

try it

 [player setContentURL: [NSURL URLWithString: [NSString stringWithFormat:@"%@%@", docPath, @"/path/to/the/movie.mov"]]]; 
+1
source

Source: https://habr.com/ru/post/1438383/


All Articles