【问题标题】:iPhone app:MpMoviePlayer not playing movie in iPad with ios5iPhone 应用程序:Movie Player 无法在 iPad 上使用 ios 5 播放电影
【发布时间】:2011-11-30 12:47:13
【问题描述】:

我在 Xcode 4 中使用基本 SDK 4.3 创建了我的 iPhone 应用

在我的 iPhone 应用程序中,我使用了 MPMovieplayercontroller 并使用它播放视频

它正在使用 IOS 4.3 在我的 iPod Touch 中播放我的视频文件,但如果我在装有 iOS 5 的 iPad 上安装相同的项目,它只显示黑屏但不播放视频。

可能出了什么问题?

这里是代码 在 .h 文件中

 MPMoviePlayerController *moviePlayer;

在 .m 文件中

 -(void)playVideo{
 NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"testbild1" ofType:@"m4v"]];
 moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
UIView *testview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[testview addSubview:moviePlayer.view];
 [self.view addSubview:testview];
  }  

   - (void)moviePlaybackComplete:(NSNotification *)notification  
   {  
    MPMoviePlayerController *moviePlayerController = [notification object];  
    [[NSNotificationCenter defaultCenter] removeObserver:self  
                                               name:MPMoviePlayerPlaybackDidFinishNotification  
                                               object:moviePlayerController];  

 [moviePlayerController.view removeFromSuperview];  


 }

【问题讨论】:

    标签: iphone objective-c ios4 ios5 mpmovieplayercontroller


    【解决方案1】:

    你好像没有设置自动播放

    shouldAutoplay
    A Boolean that indicates whether a movie should begin playback automatically.
    
    @property (nonatomic) BOOL shouldAutoplay
    

    比如:

    moviePlayer.shouldAutoplay = true;
    

    您还应该调用prepareToPlay 并使用MPMoviePlayerController 实现的MPMediaPlayback 协议

    旧帖(应该是评论):

    什么版本的iOS? iOs 5.1 beta 刚刚发布并改变了 MPMoviePlayerController 的工作方式。

    您可以在 Apple 的 iOS 测试版网站上获取详细信息,但我无法在此处打印它们 YAY EULA。


    编辑

    既然操作系统是公开的,这里是相关文档(注册——你可能还需要支付 100 美元,我忘了...)

    【讨论】:

    • 这是 iOS 5 而不是 iOS 5.1 beta。所以你有什么建议?我应该去 iOS 5.1 Beta
    • 我是否应该写这些拖线 [moviePlayer prepareToPlay]; [电影播放器​​播放];
    • 是的,这是实例化视频播放器的正确方法。
    • tkone,由于 iOS 5.1 SDK 已经公开,您能否解释/提供解释 5.1 中 MPMoviePlayerController 更改的文档的链接?
    • 我明白了,谢谢。我知道prepareToPlay,因为它记录在iOS 5.0 中,但我仍然观察到5.0 和5.1 的MPMoviePlayerController 之间的不同行为,所以我认为我遗漏了一些东西。不过感谢您的更新!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多