MPMoviePlayerController不适用于文档文件夹中的影片

我有一个播放电影的ViewController。 如果下载了电影(使用ASI-HTTP-Request),则需要使用本地版本。 否则它将从网络流式传输。 这是完全相同的电影。

流媒体确实工作得很好,但播放本地文件不起作用。 只是一个黑屏,没有控制。 文件已正确下载我检查了md5校验和。

这是一个尺寸为1024x5xx像素的Apple QuickTimevideo(.mov)。

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] 

我试过玩家MediaSourceType。 但它没有帮助。 为什么不起作用? 我没有任何错误消息,因为我没有收到一个…,有没有办法从中获取错误消息?

我发现了我的错误。

我使用[NSURL URLWithString: @"/the/path/..."]作为本地路径。

它适用于[NSURL fileURLWithPath: @"/the/path/..."]

检查video文件的URL。 此行返回Documents目录的路径。

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

您的路径与文档目录无关

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

尝试这个

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