MPMoviePlayerController无法从Docume

MPMoviePlayerController无法从Docume

本文介绍了MPMoviePlayerController无法从Documents文件夹中播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Desperated。
各位大家好!
我在使用MPMoviePlayerController时遇到了一些问题。
我已经使用了NSBundle的视频。但这不是我需要的。我需要从Documents目录中播放它,因为这是我存储录制视频的地方,其中URL存储在CoreData中。但是让我们把它放在一边,并将代码简化到最低限度。如果使用contentURL,这个代码实际上是有效的,导致NSBundle。在它之后,我做了什么来到文档的地方。
我的工作:

Desperated.Hello everybody!I am having some issues with MPMoviePlayerController.I've made it working with videos from NSBundle. But that's not what I need. I need to play it from Documents directory, because that is the place I store the recorded videos, wich URLs are stored in CoreData. but lets leave this aside, and simplify the code to its minimum needed. This code actually WORKS if using the contentURL, wich leads to NSBundle. After it, what I do to get to the docs place.What I do:

    NSURL *contentURL = [[NSBundle mainBundle] URLForResource:@"Oct_08_2012_10_00_51" withExtension:@"mp4"]; // this works
NSString* docPath = [NSSearchPathForDirectoriesInDomains
                     (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString * docaPathFull = [NSString stringWithFormat:@"%@%@", docPath, @"/Oct_08_2012_10_00_51.mp4"];
NSURL * docUrl= [NSURL URLWithString: docaPathFull];
BOOL ex = [[NSFileManager defaultManager] fileExistsAtPath:docaPathFull];
NSLog(@"file exists: %d, path using docPath: %@",ex, docaPathFull);
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:docUrl];
player.shouldAutoplay = YES;
player.controlStyle = MPMovieControlStyleEmbedded;
[player.view setFrame: self.thumbButton.bounds];
[player prepareToPlay];
[self.view addSubview: player.view];
[player play];

我们拥有什么:

2012-10-08 13:14:43.532 Voto[11968:907] file exists: 1, path using docPath: /var/mobile/Applications/07B8574A-A3BA-4B23-BB3F-995B33A01B95/Documents/Oct_08_2012_10_00_51.mp4
2012-10-08 13:14:43.907 Voto[11968:907] content URL: file://localhost/var/mobile/Applications/07B8574A-A3BA-4B23-BB3F-995B33A01B95/Voto.app/Oct_08_2012_10_00_51.mp4
2012-10-08 13:14:44.265 Voto[11968:907] doc URL: /var/mobile/Applications/07B8574A-A3BA-4B23-BB3F-995B33A01B95/Documents/Oct_08_2012_10_00_51.mp4
2012-10-08 13:14:45.343 Voto[11968:907] [MPAVController] Autoplay: Disabling autoplay for pause
2012-10-08 13:14:45.344 Voto[11968:907] [MPAVController] Autoplay: Disabling autoplay
2012-10-08 13:14:46.518 Voto[11968:907] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-10-08 13:14:46.540 Voto[11968:907] [MPAVController] Autoplay: Enabling autoplay
2012-10-08 13:14:46.554 Voto[11968:907] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
2012-10-08 13:14:46.555 Voto[11968:907] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
2012-10-08 13:14:46.557 Voto[11968:907] [MPAVController] Autoplay: Enabling autoplay
2012-10-08 13:14:46.567 Voto[11968:907] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
2012-10-08 13:14:46.871 Voto[11968:907] [MPAVController] Autoplay: Enabling autoplay

所以,该文件存在...
我看过的问题:

So, the file exists...Questions i've looked through:

我还检查过类的引用,没有具体的文档播放。
我的项目设置:
使用最新的iOS 6,
部署目标5.0
测试iOS6 iPhone模拟器和带iOS 6的iPad。
如果我忘记添加请提醒我,我会马上做的。

I also checked ut with class reference, nothing specific about playing from Documents.My projects settings:using latest iOS 6,Deployment target 5.0Testing on both iOS6 iPhone simulator and an iPad with iOS 6.If i forgot to add something, please remind me, I will do it immediately.

请帮忙! :)

推荐答案

你没有以正确的方式构建文件URL,你应该这样做:

Well you'r not building the file URL the correct way, you should do it like this:

NSString *docPath = [NSSearchPathForDirectoriesInDomains
                     (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *docaPathFull = [docPath stringByAppendingPathComponent:@"/Oct_08_2012_10_00_51.mp4"];
NSURL *docUrl= [NSURL fileURLWithPath:docaPathFull];

您应该将目录和文件添加到 stringByAppendingPathComponent NSString 的方法;
同样在创建文件URL时,在 NSURL 上使用 fileURLWithPath:,这将为此创建一个正确的NSURL给路径。

You should add directories and file to a path with the stringByAppendingPathComponent method of NSString;Also when creating the file URL use fileURLWithPath: on NSURL, this willl create a correct NSURL for the giving path.

这篇关于MPMoviePlayerController无法从Documents文件夹中播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 16:28