MPMoviePlayer 加载并播放应用程序文档中保存的电影
我正在编写一个应用程序,将照片卷中的电影存储到应用程序的本地文档文件夹中。我可以使用 MPMoviePlayer 播放远程电影,但是尝试播放存储在应用程序文档文件夹中的电影总是返回 MPMovieLoadStateUnknown
。
通知均从默认通知中心(MPMoviePlayerLoadStateDidChangeNotification
、MPMoviePlayerPlaybackDidFinishNotification
)发送和接收。 在控制台中收到 loadStateUnknown 消息后不久就会出现一个警告框,表示电影无法播放,然后应用程序会收到电影播放完成的通知。
我认为可能是找不到文件名(MPMoviePlayer只能采用URL作为资产位置)的情况。有没有人处理过这个问题或类似问题?
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
.
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
鉴于其他答案似乎都无法解决问题,我倾向于认为问题可能出在您正在生成的文档文件路径上。
您应该使用以下方法生成应用程序文档文件夹的路径:
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:
您是否尝试过将本地文件路径转换为 url
如果文件路径中有空格,则必须在创建 URL 之前将其转换
have you tried converting the local file path to a url
if there are spaces in you file path, you will have to convert them prior to creating the URL
核心数据模板将文件路径转换为 URL,如下所示:
这似乎执行了所有正确的空格转义等操作,因为我使用它来加载路径中带有空格的文件。
The Core Data template converts a file path to a URL like this:
That seems to do all of the correct space escaping and stuff because I'm using this to load a file with a space in the path.
我不确定这是否会对您有帮助。
在本教程中,有一些代码行可能会带您走上正确的道路:
您将在以下方法中找到此代码片段:
这是本教程的链接:
教程
希望这会对您有所帮助...
I am not sure if this will help you.
In this tutorial there are some code lines which probably will bring you on the right path:
You will find this snippet in following method:
here is the link to the tutorial:
Tutorial
Hopefully this will help you...