MPMoviePlayerController – 检测和不同上一页/下一页button

我已经通过下面的代码实现了检测prev / nextbutton的点击,但是还没有find区分两次点击的方法。

@implementation MyMovieController:MPMoviePlayerController

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

并定义– (void)movieChangeCallBack:(NSNotification *)aNotification

 - (void)movieChangeCallBack:(NSNotification*) aNotification { if (self.playbackState == MPMoviePlaybackStateStopped) { //Touched 'Previous' or 'Next' button. } } 

有没有办法判断“上一个”或“下一个”button是否被点击? 谢谢 :)

不幸的是,默认情况下, MPMoviePlayerPlaybackStateDidChangeNotification在点击Prev或Next时触发MPMoviePlayerPlaybackStateDidChangeNotification 。 无法唯一地通知每个人是否被窃听。

我发现的唯一方法是为后向和前向创build我自己的自定义控件,添加一个目标来执行一个动作:

 [prevBtn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside]; [nextBtn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside]; 

然后在你的onClick方法中:

  (void)onClick:(UIButton*)sender { if (sender == prevBtn) { // Do whatever when prevBtn is tapped } else if (sender == nextBtn) { // Do whatever when nextBtn is tapped } } 

仅供参考:您必须将播放器的controlStyle属性设置为MPMovieControlStyleNon以隐藏默认控件。

MPMoviePlayerController / MPMoviePlayerPlaybackStateDidChangeNotification NS_DEPRECATED_IOS(3_2,9_0)已被弃用。 你应该切换到AVPlayer。