2016-01-13 76 views
1

我已经实现了通过下面的代码检测到prev/next按钮的点击,但是还没有找到区分两次点击的方法。在MPMoviePlayerController - 检测和区别上一个/下一个按钮

@implementation MyMovieController:的MPMoviePlayerController

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

,并定义- (空)movieChangeCallBack:(NSNotification *)aNotification

- (void)movieChangeCallBack:(NSNotification*) aNotification { 

    if (self.playbackState == MPMoviePlaybackStateStopped) 
    { 
     //Touched 'Previous' or 'Next' button. 
    } 
} 

有没有办法来告诉是否“上一个“或”下一个“按钮被点击? 谢谢:)

回答

1

不幸的是,MPMoviePlayerController,默认情况下,当或者一个或下被窃听触发关闭MPMoviePlayerPlaybackStateDidChangeNotification。无法唯一通知每个人是否被窃听。

我发现的唯一途径,是创建自己的自定义控制的向后和向前,增加一个目标是要执行的动作:在你的onClick方法

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

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

然后:

(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以隐藏默认控件。

+0

谢谢:)我会试试! – veslam

0

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

相关问题