xcode 如何在 iPad 上以全屏模式捕获 MPMoviePlayer 下一个按钮单击事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3384435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:35:15  来源:igfitidea点击:

How do I catch the MPMoviePlayer next button click event while in fullscreen mode on the iPad?

objective-cxcodeipadmpmovieplayercontrollermpmovieplayer

提问by Liam

When the MPMoviePlayerViewControlleris in fullscreen mode on the iPad, it defaults to having its controls to have a previous and next button on the overlay there. In my project I need to capture the click for that overlay button and handle it accordingly. Since I'm not sure how to invoke a playlist just yet there is no next item and clicking on the button breaks the view once I exit fullscreen mode. Somehow it just doesn't know what to do and I get no errors.

MPMoviePlayerViewControlleriPad 处于全屏模式时,它的控件默认在覆盖层上有一个上一个和下一个按钮。在我的项目中,我需要捕获该叠加按钮的点击并相应地处理它。因为我不确定如何调用播放列表,所以没有下一个项目,一旦我退出全屏模式,点击按钮就会中断视图。不知何故,它只是不知道该怎么做,而且我没有收到任何错误。

What I would like to know is if there a way to listen/catch that event from the fullscreennext and previous buttons?

我想知道是否有办法从fullscreen下一个和上一个按钮侦听/捕获该事件?

I have also tried to get an overlay with my own controls to live on the MPMoviePlayer, MPMoviePlayerController, and the MPMoviePlayerViewControllerwith no success. Once the player enters fullscreenmode any overlay that was present is ignored and not carried along with the screen zooming.

我也试图让一个覆盖用我自己的控制住在MPMoviePlayerMPMoviePlayerControllerMPMoviePlayerViewController没有成功。一旦玩家进入fullscreen模式,任何存在的覆盖都将被忽略,并且不会随着屏幕缩放一起进行。

Is there a reliable way to have an overlay while in fullscreenmode? I have looked at the sample from Apple but this seems to not work for me to actually add anything to the view while in fullscreenmode.

有没有一种可靠的方法可以在fullscreen模式下进行叠加?我已经查看了 Apple 的示例,但这似乎对我在fullscreen模式下向视图添加任何内容似乎不起作用。

Any help would be appreciated.

任何帮助,将不胜感激。

回答by Seamus Campbell

I haven't used MPMoviePlayerViewController, but here are some thoughts based on peeking at the documentation.

我没有使用过 MPMoviePlayerViewController,但这里有一些基于查看文档的想法。

It looks like the MPMoviePlayerController has some notifications that might be relevant, though I don't see specific references to "next and previous buttons". Might they be Seek buttons?

看起来 MPMoviePlayerController 有一些可能相关的通知,但我没有看到对“下一个和上一个按钮”的具体引用。它们可能是搜索按钮吗?

Register for the notification with

注册通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackStateChanged:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];

And add this function to your object:

并将此函数添加到您的对象中:

-(void)moviePlayerPlaybackStateChanged:(NSNotification *)notification {
    MPMoviePlayerController *moviePlayer = notification.object;
    MPMoviePlaybackState playbackState = moviePlayer.playbackState;
    // ...
}

I suspect you'll find that you're getting MPMoviePlaybackStateSeekingForward and ...SeekingBackward updates for those buttons.

我怀疑您会发现您正在为这些按钮获取 MPMoviePlaybackStateSeekingForward 和 ...SeekingBackward 更新。

回答by Seamus Campbell

Here's another possibility I just stumbled across. The MPMoviePlayerController in full-screen mode may be sending Remote Control events. Catch these (iOS 4 only, by the way) by enabling remote control event messages in your view controller:

这是我偶然发现的另一种可能性。全屏模式下的 MPMoviePlayerController 可能正在发送远程控制事件。通过在视图控制器中启用远程控制事件消息来捕捉这些(顺便说一下,仅限 iOS 4):

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];

and then implement

然后执行

[UIResponder remoteControlReceivedWithEvent:(UIEvent*)event];

and when the view goes away, unregister in viewWillDisappear:

当视图消失时,在 viewWillDisappear 中取消注册:

[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];

I'm not certain that this will work, but it's worth a shot.

我不确定这会奏效,但值得一试。

回答by alones

Seaamsu Campbell is right :) Using his approach I got events of playback control events. See my question and answer.

Seaamsu Campbell 是对的 :) 使用他的方法我得到了回放控制事件的事件。看我的问答。

How can I know users click fast forward and fast rewind buttons on the playback controls in iPhone

我怎么知道用户点击了 iPhone 播放控件上的快进和快退按钮