【问题标题】:MPMoviePlayer - black screen - iOS 5 - no video playingMPMoviePlayer - 黑屏 - iOS 5 - 没有视频播放
【发布时间】:2011-10-28 14:29:33
【问题描述】:

在 iOS 4 中,这段代码可以播放电影:

-(IBAction)playMovie:(id)sender
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"testbild1" ofType:@"m4v"]];
    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    UIView *testview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];

    [testview addSubview:moviePlayer.view];
    [self.view addSubview:testview];
    //[self.view addSubview:moviePlayer.view];
    //[moviePlayer setFullscreen:YES animated:YES];
}  

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

    [moviePlayerController.view removeFromSuperview];  
    //[moviePlayerController release];  
}  

现在,我只得到一个黑屏。没有控制,什么都没有。视频路径是正确的,我测试过了。如果我通过按钮单击添加一个白色的子视图,它就可以工作。所以方法被调用了。

提前致谢!

【问题讨论】:

    标签: ios media-player mpmovieplayercontroller


    【解决方案1】:

    我已经通过放入 .h 文件解决了这个问题

    MPMoviePlayerController *moviePlayer;
    

    带有 ARC 的 iOS 5 与 iOS 4 的工作方式不同。

    .m 文件必须是:

    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    

    【讨论】:

    • 我做了同样的事情(但在另一个项目中),我故意这样说,而且效果很好。所以我认为就是这样。感谢您的贡献。
    • 这可以与PhoneGap一起使用吗?我不确定如何/在哪里使用该框架实施修复
    • WTF。在另一个项目中再次犯了同样的错误,这个错误是解决方案 AGAIN ...
    【解决方案2】:

    如果您使用的是 iOS 5.0 或 5.1,请检查您的 moviePlyer 是否有如下设置。

    [moviePlayer setControlStyle:MPMovieControlStyleFullscreen];

    如果是这样,当你设置[moviePlayer setFullScreen:YES animated:YES]; 然后将调用 MPMoviePlayerPlaybackDidFinishNotification 通知而不是调用 MPMoviePlayerWillExitFullscreenNotification 或 MPMoviePlayerDidExitFullscreenNotification

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多