10

When using the MPMoviePlayerController, the play button is surrounded with "Next" and "Previous" buttons.

How do I get notifications when they are clicked? is there a way to feed MPMoviePlayerController with a list (array) of content?

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
David Salzer
  • 872
  • 1
  • 7
  • 24
  • I found a way, see my question and answer. http://stackoverflow.com/questions/3593683/how-can-i-know-users-click-fast-forward-and-fast-rewind-buttons-on-the-playback-c/3598383#3598383 – alones Aug 30 '10 at 06:41

3 Answers3

6

Nathan is correct about needing to implement your own UI for the player if you want button notifications. You can get notifications from the player about playback state though.

from the AddMusic example, where self is the controller or model containing the instance of MPMusicPlayerController:

- (void) registerForMediaPlayerNotifications {

    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

    [notificationCenter addObserver: self
                           selector: @selector (handle_NowPlayingItemChanged:)
                               name: MPMusicPlayerControllerNowPlayingItemDidChangeNotification
                             object: musicPlayer];

    [notificationCenter addObserver: self
                           selector: @selector (handle_PlaybackStateChanged:)
                               name: MPMusicPlayerControllerPlaybackStateDidChangeNotification
                             object: musicPlayer];

    /*
     // This sample doesn't use libray change notifications; this code is here to show how
     //     it's done if you need it.
     [notificationCenter addObserver: self
     selector: @selector (handle_iPodLibraryChanged:)
     name: MPMediaLibraryDidChangeNotification
     object: musicPlayer];

     [[MPMediaLibrary defaultMediaLibrary] beginGeneratingLibraryChangeNotifications];
     */

    [musicPlayer beginGeneratingPlaybackNotifications];
}
4

No notifications are generated when the user presses the next/previous buttons (you should file a bug about that), so the only way to solve this without any unapproved view-crawling is to implement your own video overlay view:

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];
}

Not ideal, but the standard controls are quite easy to re-implement.

Nathan de Vries
  • 15,481
  • 4
  • 49
  • 55
0

I don't think you have much control over the MPMoviePlayerController. It is a standard component that can basically start and stop playing a movie and nothing else.

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
Stefan Arentz
  • 34,311
  • 8
  • 67
  • 88
  • I guess you are right. And yet, why these controls are there anyway? On the youTube application - they do move to the next/prev video. – David Salzer Jul 16 '09 at 11:28
  • On the iPhone they go to the start or end of the current movie. They are not next/prev buttons. – Stefan Arentz Jul 16 '09 at 12:12
  • That is incorrect. When you implement am MPMoviePlayerController - they just exit the player in the same way "stop" would do. – David Salzer Jul 16 '09 at 17:12