1

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

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

这是一个大小为 1024x5xx 像素的 Apple QuickTime 视频 (.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/..."]

4

1 回答 1

1

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

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

您的路径与 Document 目录无关

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

尝试这个

[player setContentURL: [NSURL URLWithString: [NSString stringWithFormat:@"%@%@", docPath, @"/path/to/the/movie.mov"]]];
于 2012-01-24T09:26:57.717 回答