English 中文(简体)
MPMoviePlayer加载并播放保存在应用程序文档中的电影
原标题:MPMoviePlayer load and play movie saved in app documents

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

我认为可能是找不到文件名(MPMoviePlayer只能将URL作为资产位置)的情况。有人处理过这个问题或类似的问题吗?

最佳回答

考虑到其他答案似乎都不能解决问题,我倾向于认为问题可能与您正在生成的Documents文件路径有关。

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

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

你试过将本地文件路径转换为url吗

[NSURL URLWithString: [NSString stringWithFormat:@"file:/%@//",filePath]];

如果文件路径中有空格,则在创建URL之前必须转换它们

filePath = [filePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
filePath = [filePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

核心数据模板将文件路径转换为URL,如下所示:

NSURL *storeUrl = [NSURL fileURLWithPath:whatever];

这似乎完成了所有正确的空间转义等操作,因为我正在使用它来加载路径中有空间的文件。

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:

    // Unless state is unknown, start playback
if ([mp loadState] != MPMovieLoadStateUnknown)
...

您将在以下方法中找到此代码段:

- (void) moviePlayerLoadStateChanged:(NSNotification*)notification 

here is the link to the tutorial: Tutorial

希望这能帮助你。。。





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签