问题
I have a ViewController which plays a movie. If the movie was downloaded (with ASI-HTTP-Request) it takes the local version. Otherwise it streams it from the web. It's the exact same movie.
Streaming does work very well, but playing the local file does not work. Just a black screen and no controls. The file has been downloaded correctly I checked the md5 checksum.
It's a Apple QuickTime Video (.mov) at a size of 1024x5xx pixel.
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 around with the players MediaSourceType. But it didn't help. Why does it not work? I don't have any error messages because I dont receive one..., is there a way to get error messages from it?
Solution
I found my error.
I used [NSURL URLWithString: @"/the/path/..."]
for the local path.
It works with [NSURL fileURLWithPath: @"/the/path/..."]
回答1:
Check URL to video file. This line return path to Documents directory.
NSString* docPath = [NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
Your path is not related to Document directory
[player setContentURL: [NSURL URLWithString: @"/path/to/the/movie.mov"]];
Try this
[player setContentURL: [NSURL URLWithString: [NSString stringWithFormat:@"%@%@", docPath, @"/path/to/the/movie.mov"]]];
来源:https://stackoverflow.com/questions/8984390/mpmovieplayercontroller-does-not-work-with-movie-in-documents-folder