我有一个视频文件保存在我的应用程序本地目录中的文档文件夹中。我想在用户点击我创建的嵌入式表格视图中的项目时播放文件。我播放视频的代码如下:
播放保存在应用程序文档目录中的视频文件
NSString* documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* path = [documentPath stringByAppendingPathComponent:@"DemoRecording.mp4"];
NSURL* movieURL = [NSURL fileURLWithPath: path];
[player.view setFrame: self.view.bounds];
[self.view addSubView: player.view];
[player play];
MPMoviePlayerViewController* moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL: movieURL];
[self presentMoviePlayerViewControllerAnimated: moviePlayer];
视频无法播放。路径是正确的,并且文件存在那里。
我知道这是一个重复的问题。我已经提到这些链接:
Playing a Downloaded Video from the Documents Directory with Cocoa-Touch
MPMoviePlayer load and play movie saved in app documents
但找不到确切答案。
请帮我解决这个问题。我正在使用iOS 5.1.1,如果这改变了任何东西。
编辑:
它确实有效。我忘记了将URL传递给电影播放器。
如果可以,请使用web视图来显示该文件。这很容易 –
你在哪里将'movieURL'传递给'player'? – Zen
你是对的我没有把URL传给玩家。我编辑了代码来包含它,它的工作原理。真诚的歉意。 –