【问题标题】:MPMoviePlayerController does not work with movie in documents folderMPMoviePlayerController 不适用于文档文件夹中的电影
【发布时间】:2012-02-17 13:19:57
【问题描述】:

我有一个播放电影的 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/..."]

【问题讨论】:

    标签: ios stream mpmovieplayercontroller mov


    【解决方案1】:

    检查视频文件的 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"]]];
    

    【讨论】:

    • 路径正确,我把代码短了。对于那个很抱歉。电影实际上位于缓存目录中。 [NSString stringWithFormat: @"%@/Library/Caches/movie.mov", NSHomeDirectory()]NSFileManager 说文件存在...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-23
    • 2014-01-02
    • 2018-09-08
    • 1970-01-01
    • 2012-10-20
    • 1970-01-01
    相关资源
    最近更新 更多