我正在将视频保存到应用程序中的特定路径。
I.E:
My Video Path is /private/var/mobile/Applications/57DBBE40-088E-48CD-AED7-9BDB8FF1E039/tmp/video_66C2B8C6-012C-4608-BA8C-97C7ABA0D721.mp4
然后我尝试在自定义框架中使用MPMoviePlayerController播放该视频。
videoPath = [stand stringForKey:@"videoPathKey"];
NSLog(@"My Video Path is %@", videoPath);
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:videoPath]];
player.view.frame = CGRectMake(0, 44, 320, 272);
[self.view addSubview:player.view];
[self.view bringSubviewToFront:player.view];
[player play];
这似乎不起作用。视频永远不会加载。知道为什么吗?
是的,我正在获得正确的视频路径。
NSLOG显示:URL为file:///private/var/mobile/Applications/57DBBE40-088E-48CD-AED7-9BDB8FF1E039/tmp/video_37794C4E-A3D0-4AC0-9964-A9DEBB61C3E2.mp4
答案 0 :(得分:0)
NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"Your VideoName" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:urlStr];
mpMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
mpMoviePlayerController.view.frame = CGRectMake(0, 0, self.playView.frame.size.width, self.playView.frame.size.height);
[self.playView addSubview:mpMoviePlayerController.view];
[mpMoviePlayerController play];
试试这个!
答案 1 :(得分:0)
这就是我过去的做法
- (MPMoviePlayerController *) loadFile:(NSString *) fileName intoView:(UIView*) videoView
{
NSString *thePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp4"];
NSURL *theurl = [NSURL fileURLWithPath:thePath];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
[moviePlayer.view setFrame:videoView.bounds];
[videoView addSubview:moviePlayer.view];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
moviePlayer.shouldAutoplay = NO;
return moviePlayer;
}
答案 2 :(得分:0)
您应该更改URL以便放置方案:
NSURL *movieURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://localhost%@",url]];
您的视频路径为: file://localhost/private/var/mobile/Applications/57DBBE40-088E-48CD-AED7-9BDB8FF1E039/tmp/video_66C2B8C6-012C-4608-BA8C-97C7ABA0D721.mp4 < /强>
我希望有帮助