MPMoviePlayer加载并播放保存在应用文档中的电影 [英] MPMoviePlayer load and play movie saved in app documents

查看:90
本文介绍了MPMoviePlayer加载并播放保存在应用文档中的电影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,将照片卷中的电影存储到应用程序的本地文档文件夹中。我可以使用MPMoviePlayer播放远程电影,但是尝试播放存储在应用程序的文档文件夹中的电影总是返回 MPMovieLoadStateUnknown

I am writing an application that stores the movies in the photo roll into the local documents folder for the app. I can play remote movies using the MPMoviePlayer, however trying to play a movie stored in the documents folder for the app always returns MPMovieLoadStateUnknown.

通知都是从默认通知中心发送和接收的( MPMoviePlayerLoadStateDidChangeNotification MPMoviePlayerPlaybackDidFinishNotification )。
警告框在控制台中收到loadStateUnknown消息后不久显示,表示无法播放电影,然后应用程序收到电影播放完成通知。

The notifications are all getting sent and received from the default notification center (MPMoviePlayerLoadStateDidChangeNotification, MPMoviePlayerPlaybackDidFinishNotification). An alert box shows up shortly after getting the loadStateUnknown message in the console, saying that the movie could not be played and the app then receives the movie playback completed notification.

我认为可能无法找到文件名(MPMoviePlayer只能将URL作为资产位置)。有没有人处理过这个问题或类似问题?

I think that it may be a case that the filename (MPMoviePlayer can only take a URL as the asset location) cannot be found. Has anyone dealt with this issue or similar?

推荐答案

鉴于其他答案似乎都没有解决问题,我是倾向于认为问题可能出在您正在生成的Documents文件路径上。

Given that none of the other answers seem to resolve the problem, I'm inclined to think that the problem might be with the Documents file path you are producing.

您应该使用以下方法生成应用程序文档文件夹的路径:

You should be using the following method to generate the path to the application's documents folder:

NSString *userDocumentsPath = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if ([paths count] > 0) 
{
     userDocumentsPath = [paths objectAtIndex:0];
}

这篇关于MPMoviePlayer加载并播放保存在应用文档中的电影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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