iOS 在全屏模式下使用 MPMoviePlayerViewController (iPad)

发布于 2024-09-29 09:11:23 字数 1267 浏览 2 评论 0原文

我有一个带有 5 个按钮的单视图应用程序,当按下其中一个按钮时,播放器会在原始视图上向上滑动并开始全屏播放视频(正如它应该的那样)。

除了按全屏/最小化图标(播放控件旁边的两个对角箭头相互指向)外,所有功能都很好。按下此按钮时,带有五个按钮的原始视图会在视频播放器上向上滑动。问题是视频仍在原始视图下播放。我真的很想消除全屏/最小化图标,但据我所知,这似乎不可能。所以...我在想,当按下全屏/最小化图标时,我也许可以使用观察者来收听,并且我可以做我需要做的事情。我只是找不到任何关于如何做到这一点的可靠信息。任何帮助/指导将不胜感激。

这是我当前的代码...

-(IBAction)playvideo {

 NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Megamind" ofType:@"mov"]];
 MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

 [self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];

 playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
 [playerController.moviePlayer play];
 [playerController release];
 playerController=nil;
}

- (void)moviePlayerWillExitFullscreen:(NSNotification *)theNotification {

 MPMoviePlayerController *playerController = [theNotification object];
 [[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(moviePlayerWillExitFullscreen:)
             name:MPMoviePlayerWillExitFullscreenNotification
              object:nil];

 [playerController stop];
 [self dismissMoviePlayerViewControllerAnimated];
}

I have a single view app with 5 buttons and when one of the buttons is pressed, the player slides up over the original view and begins playing the video in fullscreen (as it should).

All works great with the exception of when pressing the Fullscreen/Minimize icon (the two diagonal arrows pointing to each other next to the play back controls). When pressing this, the original view with the five buttons slides up over the video player. The problem is the video is still playing underneath the original view. I would really like to eliminate the Fullscreen/Minimize icon but from I can tell, that does not seem possible. So... I am thinking, I might be able to use an observer to listen to when the Fullscreen/Minimize icon is pressed and I can do what I need to. I just can not find anything solid on how to do this. Any help/direction would be greatly appreciated.

Here is my current code...

-(IBAction)playvideo {

 NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Megamind" ofType:@"mov"]];
 MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

 [self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];

 playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
 [playerController.moviePlayer play];
 [playerController release];
 playerController=nil;
}

- (void)moviePlayerWillExitFullscreen:(NSNotification *)theNotification {

 MPMoviePlayerController *playerController = [theNotification object];
 [[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(moviePlayerWillExitFullscreen:)
             name:MPMoviePlayerWillExitFullscreenNotification
              object:nil];

 [playerController stop];
 [self dismissMoviePlayerViewControllerAnimated];
}

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

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

发布评论

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

评论(4

假装不在乎 2024-10-06 09:11:23

这条线导致了你的行为。

[self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];

它与常规的 presentModalViewController 方法非常相似。

它以模态方式呈现电影播放器​​及其视图控制器。所以这里的默认设置就是

movieplayer.controlStyle = MPMovieControlStyleFullScreen

默认设置的。

因此,当您按下这些对角箭头时,它会退出该模式,并发出通知。但是您必须首先设置一个观察者来监听该通知,就像电影完成时所做的那样。

您做了

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

这会添加一个通知以观察电影完成通知。
要退出全屏模式,请再添加一个观察者,即:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieExitFullScreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];

添加 -(void) movieExitFullScreen:(NSNotification *) 选择器后就可以了。希望有帮助。 :)

This line is causing you that behaviour.

[self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];

It is pretty much similar to your regular presentModalViewController method.

It presents the Movieplayer and its view controller Modally. So the default settings here are

movieplayer.controlStyle = MPMovieControlStyleFullScreen

which are set up by default.

So when you press those diagonal arrows, it exits that mode, and gives a notification for that. But you have to setup an observer first to listen to that notifcation as you did for movie finished.

You did

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

This adds a notification to observe for movie completion notifications.
For exiting full screen mode add one more observer that is this..

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieExitFullScreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];

And you should be good to go after adding the -(void) movieExitFullScreen:(NSNotification *) selector for the same. Hope it helps. :)

挽清梦 2024-10-06 09:11:23

将此行放在 MPMoviePlayer 的 init 之后:

[[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(moviePlayerWillExitFullscreen:)
             name:MPMoviePlayerWillExitFullscreenNotification
              object:nil];

Put this line just after the init of your MPMoviePlayer :

[[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(moviePlayerWillExitFullscreen:)
             name:MPMoviePlayerWillExitFullscreenNotification
              object:nil];
庆幸我还是我 2024-10-06 09:11:23

我认为您正在将观察者添加到您想要删除它的方法中。

您希望

MPMoviePlayerController *playerController = [theNotification object]; 
[[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(moviePlayerWillExitFullscreen:)
         name:MPMoviePlayerWillExitFullscreenNotification
          object:nil];

在 playVideo() 中

使用它,

[[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:name:MPMoviePlayerWillExitFullscreenNotificationn
                                                  object:nil];

在 moviePlayerWillExitFullscreen 方法中使用它。

I think you're adding the observer in the method where you want to be REMOVING it.

You want this

MPMoviePlayerController *playerController = [theNotification object]; 
[[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(moviePlayerWillExitFullscreen:)
         name:MPMoviePlayerWillExitFullscreenNotification
          object:nil];

in the playVideo()

and THIS

[[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:name:MPMoviePlayerWillExitFullscreenNotificationn
                                                  object:nil];

in the moviePlayerWillExitFullscreen method.

灼痛 2024-10-06 09:11:23

我确实找到了解决方案,但由于缺乏知识,我无法完全理解它为什么会这样工作。我很抱歉没有进行彻底的推理。在我的原始代码中... MPMoviePlayerWillExitFullscreenNotification 没有响应点击。对于 MPMoviePlayerDidExitFullscreenNotification 也是如此。回答的是 MPMoviePlayerPlaybackDidFinishNotification。这是工作代码,了解 MPMoviePlayerPlaybackDidFinishNotification 正在工作并且也应用于全屏/嵌入印刷机。

-(IBAction)playvideo {

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Megamind" ofType:@"mov"]];
MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

[self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];

playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playerController.moviePlayer play];
[playerController release];
playerController=nil;
NSLog(@"playvideo");
}

- (void)movieFinishedPlayback:(NSNotification*)notification {

            MPMoviePlayerController *playerController = [notification object];
            [playerController pause];
            [self dismissMoviePlayerViewControllerAnimated];

}

I did find a solution and my lack of knowledge put me in a situation where I do not fully understand why it works this way. My apologies for not having a thorough reasoning. In my original code... the MPMoviePlayerWillExitFullscreenNotification was not answering to taps. This is true for MPMoviePlayerDidExitFullscreenNotification as well. What was answering was MPMoviePlayerPlaybackDidFinishNotification. Here is teh working code in knowing that the MPMoviePlayerPlaybackDidFinishNotification was working and also applied to the Fullscreen/Embed presses.

-(IBAction)playvideo {

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Megamind" ofType:@"mov"]];
MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

[self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];

playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playerController.moviePlayer play];
[playerController release];
playerController=nil;
NSLog(@"playvideo");
}

- (void)movieFinishedPlayback:(NSNotification*)notification {

            MPMoviePlayerController *playerController = [notification object];
            [playerController pause];
            [self dismissMoviePlayerViewControllerAnimated];

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