MPMoviePlayerController - Detect and Differ Prev/Next buttons

拥有回忆 提交于 2019-12-13 00:49:00

问题


I've achieved detecting the click of prev/next button by following code, but still haven't found an way to distinguish the two clicks.

in @implementation MyMovieController : MPMoviePlayerController

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

and define - (void) movieChangeCallBack:(NSNotification*) aNotification

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

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

Is there a way to tell whether the 'previous' or 'next' button is clicked? Thanks :)


回答1:


Unfortunately, MPMoviePlayerController, by default, fires off MPMoviePlayerPlaybackStateDidChangeNotification when either the Prev or Next is tapped. There's no way to uniquely be notified whether each one is tapped.

The only way I found, was to create my own custom controls for backward and forward, adding a target to it to perform an action:

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

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

Then in your onClick method:

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

FYI: you must set the player's controlStyle property to MPMovieControlStyleNon to hide the default controls.




回答2:


MPMoviePlayerController/MPMoviePlayerPlaybackStateDidChangeNotification NS_DEPRECATED_IOS(3_2, 9_0) is deprecated. You should switch over to AVPlayer.



来源:https://stackoverflow.com/questions/34759244/mpmovieplayercontroller-detect-and-differ-prev-next-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!