Dum*_*oko 4 nsurl mpmovieplayercontroller ios nsdocumentdirectory
Desperated.大家好!我在使用MPMoviePlayerController时遇到了一些问题.我已经使用了NSBundle的视频.但那不是我需要的.我需要从Documents目录中播放它,因为这是我存储录制视频的地方,其中URL存储在CoreData中.但是让我们把它放在一边,并将代码简化到最低要求.如果使用contentURL,这段代码实际上是可行的,导致NSBundle.在它之后,我做了什么来到文档的地方.我所做的:
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];
Run Code Online (Sandbox Code Playgroud)
我们有什么:
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
Run Code Online (Sandbox Code Playgroud)
所以,文件存在...我看过的问题:
MPMoviePlayerController不适用于文档文件夹中的影片
MPMoviePlayerViewController播放来自Documents目录的电影 - objective-c
我还检查了类参考,没有具体关于从文档播放.我的项目设置:在iOS6 iPhone模拟器和iOS 6的iPad上使用最新的iOS 6,部署目标5.0测试.如果我忘了添加内容,请提醒我,我会立即执行.
请帮忙!:)
rck*_*nes 20
你没有以正确的方式构建文件URL,你应该这样做:
NSString *docPath = [NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *docaPathFull = [docPath stringByAppendingPathComponent:@"/Oct_08_2012_10_00_51.mp4"];
NSURL *docUrl= [NSURL fileURLWithPath:docaPathFull];
Run Code Online (Sandbox Code Playgroud)
您应该添加目录和文件与路径stringByAppendingPathComponent的方法NSString; 此外,当创建文件URL使用fileURLWithPath:时NSURL,这将为给定路径创建正确的NSURL.
Fah*_*kar 10
每个人都做的最常见的错误就是全部使用
NSURL *fileURL = [NSURL URLWithString:mVidPath];
^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
代替
NSURL *fileURL = [NSURL fileURLWithPath:mVidPath];
^^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4385 次 |
| 最近记录: |