MPMoviePlayerController不适用于文档文件夹中的影片 [英] MPMoviePlayerController does not work with movie in documents folder

查看:132
本文介绍了MPMoviePlayerController不适用于文档文件夹中的影片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

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

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]

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

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?

解决方案

我发现了我的错误。

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

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

推荐答案

检查网址到视频文件。此行返回文档目录的路径。

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"]];

试试这个

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

这篇关于MPMoviePlayerController不适用于文档文件夹中的影片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆