MPMoviePlayerViewController 从文档目录播放电影 - Objective-c
我在文档文件夹中有一个名为“视频”的子文件夹。还有一些video.mp4文件。我有此文件的完整路径,但 MPMoviePlayerViewController 不想从本地播放视频。这是代码:
NSString *path = [[self getVideoFolderPath] stringByAppendingPathComponent:@"somevideo.mp4"];
NSURL *fURL = [NSURL fileURLWithPath:path];
MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:fURL];
[self presentMoviePlayerViewControllerAnimated:videoPlayerView];
[videoPlayerView.moviePlayer play];
它不播放。出现白屏,没有其他内容。当我将 URL 放入包含视频文件的网站时,此代码适用于远程视频,但本地无法播放。如何获取视频文件的正确文件路径?
I have subfolder called "Video" in Documents folder. And there is somevideo.mp4 file. I have full path to this file but MPMoviePlayerViewController doesn't want to play video from local. Here is code:
NSString *path = [[self getVideoFolderPath] stringByAppendingPathComponent:@"somevideo.mp4"];
NSURL *fURL = [NSURL fileURLWithPath:path];
MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:fURL];
[self presentMoviePlayerViewControllerAnimated:videoPlayerView];
[videoPlayerView.moviePlayer play];
It doesn't play. Appears white screen and nothing else. This code works with remote video, when i put URL to website with video file, but local doesn't play. How to get correct file path to video file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用的是 4.3 之前的 iOS 系统吗?如果是这样,您需要执行此操作
这是我从文档文件夹中播放视频的代码片段。我建议的一件事是避免某些自动释放对象。特别是当你有视图控制器时,在 NSURL 上。我知道它应该是安全的,但我从未发现它是 100%
在我的例子中,我创建了 MPMoviePlayerController 的子类(就像我通常对所有视图控制器所做的那样),因此对“self”的引用将是 MPMoviePlayerController 对象实例
Are you using iOS prior to 4.3? If so, you need to do this
Here is a snippet of code from where I play video from the documents folder. One of the things I would recommend is to avoid some of the autorelease objects. Especially on NSURL when you have viewcontrollers. I know it should be safe but I've never found it to be 100%
In my case, I created a subclass of MPMoviePlayerController (as I generally do with all view controllers) so the references to 'self' would be to the MPMoviePlayerController object instance
奇怪的。您输入的代码似乎是正确的。确保您尝试检索的音频的路径没有损坏。
Strange. The code you put seems to be correct. Make sure the path to the audio you are trying to retrieve isn't broken.