MPMoviePlayer - 黑屏 - iOS 5 - 没有视频播放

发布于 2024-12-12 07:18:53 字数 1153 浏览 8 评论 0原文

在 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];  
}  

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

提前致谢!

In iOS 4 this Code worked to play a movie:

-(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];  
}  

Now, I only get a blackscreen. No controls, nothing. Video path is correct, I tested that. If I add just a white Subview by button click, it works. So the method is called.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖上的星空 2024-12-19 07:18:54

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

MPMoviePlayerController *moviePlayer;

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

文件必须是:

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

I have solved the issue by putting in the .h file

MPMoviePlayerController *moviePlayer;

iOS 5 with ARC works differently than iOS 4.

The .m file must be:

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
拿命拼未来 2024-12-19 07:18:54

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

[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];

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

If you are on iOS 5.0 or 5.1, check your moviePlyer has a setting like below.

[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];

If so, when you set [moviePlayer setFullScreen:YES animated:YES];
then MPMoviePlayerPlaybackDidFinishNotification notification will be called instead of being called MPMoviePlayerWillExitFullscreenNotification or MPMoviePlayerDidExitFullscreenNotification

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文