ios – MPMoviePlayerController不播放本地文件

Nsstring *path = [[NSBundle mainBundle] pathForResource:@"PTCL" ofType:@"mp4"];    
  NSURL *videoURL = [NSURL URLWithString:path];    
        MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];    
        [moviePlayerController.view setFrame:self.view.frame];
        [self.view addSubview:moviePlayerController.view]; 
        moviePlayerController.controlStyle=MPMediaTypeAnyVideo;
        moviePlayerController.fullscreen = YES;
        [moviePlayerController preparetoPlay];
        [moviePlayerController play];
Nsstring *path = [[NSBundle mainBundle] pathForResource:@"PTCL" ofType:@"mp4"];   

path=[Nsstring stringWithFormat:@"file:/%@",path];   
NSURL *videoURL = [NSURL URLWithString:path];

MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

[moviePlayerController.view setFrame:self.view.frame];
[self.view addSubview:moviePlayerController.view];

moviePlayerController.shouldAutoplay=YES;
moviePlayerController.controlStyle=MPMediaTypeAnyVideo;
moviePlayerController.fullscreen = YES;
[moviePlayerController preparetoPlay];
[moviePlayerController play];

> file:/// Users / utkal / Library / Application Support / iPhone Simulator / 7.0.3 / Applications / F0B3AD63-7E46-4069-8845-8B0C05425CD2 / CosMos.app / PTCL.mp4

我得到第一个代码的videURL路径

> file:/// Users / utkal / Library / Application Support / iPhone Simulator / 7.0.3 / Applications / F0B3AD63-7E46-4069-8845-8B0C05425CD2 / CosMos.app / PTCL.mp4

我正在获取第二个代码的videURL路径.

我有alos使用

NSURL *videoURL = [[NSURL alloc]init];
    videoURL = [[NSBundle mainBundle] URLForResource:@"PTCL" withExtension:@"mp4"];

但我的视频播放器总是显示文件正在加载,没有任何反应.
我知道我在哪里做错了,但我的运气不好.
请更正我的错误或告诉我是否有其他方式播放本地视频文件.请.

解决方法

也许为时已晚,但我会尝试这样的事情:
MPMoviePlayerViewController *movieVC = [[MPMoviePlayerViewController alloc] initWithContentURL:file.location];
movieVC.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
movieVC.moviePlayer.fullscreen = YES;
movieVC.moviePlayer.allowsAirPlay = YES;
movieVC.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[self presentMoviePlayerViewControllerAnimated:movieVC];

注意“movieVC.movi​​ePlayer.movi​​eSourceType = MPMovieSourceTypeFile;”

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...