ios - MPMoviePlayerController 不播放本地文件

标签 ios iphone ios7 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%20Support/iPhone%20Simulator/7.0.3/Applications/F0B3AD63-7E46-4069-8845-8B0C05425CD2/CosMos.app/PTCL.mp4

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

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

我正在为第二个代码获取此 videURL 路径。

我也用过

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

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

enter image description here

最佳答案

也许为时已晚,但我会尝试类似的方法:

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;”

关于ios - MPMoviePlayerController 不播放本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21177152/

相关文章:

ios - 创建像 iOS 7 Safari 的共享/书签菜单一样的向上滑动菜单

ios - 如何检测弹出窗口关闭

ios - SceneKit 中的场景渲染不正确

iOS Xcode Swift 将输入名字和姓氏组合成全名问题

iphone - 使用 CALayer 创建 .PNG 的笔触/轮廓?

ios - 自 ios7 起,indexPathForCell 返回 nil

ios - Swift 1.2 - 由类函数的闭包参数引起的错误

iphone - 通过 iPhone 应用程序以字符串形式读取 PDF 文件

iphone - 使用 NSMutablearray 数据更改 UILabel 中的文本

ios - 键盘未显示