11

I'm using MPMoviePlayerController and I need to detect pressing Next/Prev buttons. I tried several things, none of which seem to works.

Here is what I tried:

  • remote control events
-(void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}  
-(void) viewWillDisappear:(BOOL)animated
{
    [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
    [self resignFirstResponder];
    [super viewWillDisappear:animated];
}  
-(BOOL)canBecomeFirstResponder
{
    return YES;
}  
-(void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent
{
    // stuff
}

The problem is remoteControlReceivedWithEvent method is never called. I've read that this will not work in iOS version higher than 6 - I'm working on iOS 7

  • notifications

I tried using MPMoviePlayerPlaybackStateDidChangeNotification and check against MPMoviePlaybackStateSeekingForward or MPMoviePlaybackStateSeekingBackward - unfortunatelly, these playback state are set when dragging the playback bar, not when pressing Next/Prev buttons.

Any ideas?

taber
  • 3,166
  • 4
  • 46
  • 72
  • http://stackoverflow.com/questions/3593683/how-can-i-know-users-click-fast-forward-and-fast-rewind-buttons-on-the-playback – Woodstock Aug 19 '14 at 11:15
  • as You can see in my post, thats the first thing I tried and it doesn't work – Jan Podgorski Aug 19 '14 at 11:18
  • Would it be that when MPMoviePlayerController shows, viewWillDisappear is called and so the receive remote control is ended? Please try to comment out the viewWillDisappear and try again. – John Nov 02 '14 at 18:08
  • @John Thanks for the suggestion, I thought the same thing, no such luck! :( – taber Nov 03 '14 at 01:49
  • Have you had a look at the MPMoviePlayerNowPlayingMovieDidChangeNotification? It tells you when the current movie playing changes, and if you have a dictionary or array with the movies you can determine whether the movie that's being played is the next or previous one. https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/#//apple_ref/c/data/MPMoviePlayerNowPlayingMovieDidChangeNotification – Emil Nov 08 '14 at 23:07
  • @Emil Yep, tried that, the notification doesn't fire after tapping previous or next. – taber Nov 10 '14 at 13:03

5 Answers5

0

Sorry I don´t understand your problem very well, but if you want use the controls out your App in the Control Center, you can use:

      // You need cath the singleton
MPRemoteCommandCenter *myRemote = [MPRemoteCommandCenter sharedCommandCenter];
//And add the selector you can fire depends on the button, a couple of examples:
[myRemote.playCommand addTarget:self action:@selector(myPlayMethods)];
[myRemote.nextTrackCommand addTarget:self action:@selector(myNextTrackMethods)];
Onik IV
  • 5,007
  • 2
  • 18
  • 23
0

try registering for event in :

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    // Turn on remote control event delivery
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

    // Set itself as the first responder
    [self becomeFirstResponder];
}

Also Don't set kAudioSessionProperty_OverrideCategoryMixWithOthers property

hariszaman
  • 8,202
  • 2
  • 40
  • 59
  • there are also solution which say to subclass Uiapplication and impelment -(void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent there did you try that? – hariszaman Nov 10 '14 at 13:19
0

Have you tried MPMoviePlayerNowPlayingMovieDidChangeNotification? If this does not work then i would suggest moving to a lower level API i.e. AVPlayer. It provides fine grained control over all the actions while video playing and otherwise.

jarora
  • 5,384
  • 2
  • 34
  • 46
0

You need to register to handle a notification for moviePlayerLoadStateChanged. When you press the next/prev buttons moviePlayerLoadStateChanged will be called and the loadState will be MPMovieLoadStateUnknown

-(void)registerMyStuff {
    [[NSNotificationCenter defaultCenter] addObserver:self
                            selector:@selector(moviePlayerLoadStateChanged:)
                                    name:MPMoviePlayerLoadStateDidChangeNotification
                                           object:self.mpc];
}

- (void)moviePlayerLoadStateChanged:(NSNotification *)notification
{
    MPMoviePlayerController *moviePlayer = notification.object;
    MPMovieLoadState loadState = moviePlayer.loadState;

    if(loadState == MPMovieLoadStateUnknown)
    {
        // this is where the next/prev buttons notify
        // there is no video in this state so load one
        // just reload the default movie

        NSLog(@"MPMovieLoadStateUnknown");
        self.mpc.contentURL = self.fileURL;
        [self.mpc prepareToPlay];

        return;
    }
    else if(loadState & MPMovieLoadStatePlayable)
    {
        NSLog(@"MPMovieLoadStatePlayable");
    }
    else if(loadState & MPMovieLoadStatePlaythroughOK)
    {
        NSLog(@"MPMovieLoadStatePlaythroughOK");
    } else if(loadState & MPMovieLoadStateStalled)
    {
        NSLog(@"MPMovieLoadStateStalled");
    }
}
n6xej
  • 461
  • 5
  • 15
0

You change MPMoviePlayerController overlayView just like change UIImagePickerController overlayView to implement the function you need.

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]
    initWithContentURL:someUrl];

moviePlayer.movieControlMode = MPMovieControlModeHidden;
[moviePlayer play];

NSArray *windows = [[UIApplication sharedApplication] windows];

if ([windows count] > 1) {

     UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
     [moviePlayerWindow addSubview:yourCustomOverlayView];
}
DShah
  • 9,768
  • 11
  • 71
  • 127
timothy lau
  • 386
  • 2
  • 2