I want to implement the following things,
- App is running a music or video (using
MPMoviePlayerController
) in background. - User double clicks the home button and go to the first screen showing playback controls (fast rewind, play or pause, fast forward buttons)
- User click fast rewind or fast forward button. Then app play previous or next music or video.
For the 3rd step, I should know which button is clicked.
(As I naturally know, the currently playing item is paused, stopped.. using MPMoviePlayerPlaybackStateDidChangeNotification
notification).
Which notification should I register? Or are there any other approaches?
I got the answer by myself.
That is using UIApplication's beginReceivingRemoteControlEvents.
In an appropriate place (like viewWillAppear:) put the following code
And the view controller should implement the following method returning YES
And then you can receive remote controller event in the following method.
And event.subtype is as below,
This might be a very late answer, but as I notice, there aren't many Q/As about audio playing and remote controls, so I hope my answer helps the others who have the same problem:
I'm using
AVAudioPlayer
at the moment, but the remote controlling method which is- (void)remoteControlReceivedWithEvent:(UIEvent *)event
must not be involved with the type of the player you're using.To get the forward and rewind buttons on lock screen work, follow this:
In your view controller's
viewDidLoad
method add the following code:Then add these methods:
viewDidAppear:
: (if not implemented already)viewWillDisappear:
(if not implemented already)And:
This is working fine in my app, however if you want to be able to receive remote control events in all view controllers, then you should set it in the
AppDelegate
.NOTE! This code is working fine at the moment, but I see two more subtypes called
UIEventSubtypeRemoteControlEndSeekingBackward
andUIEventSubtypeRemoteControlEndSeekingBackward
. I'm not sure if they have to be implemented or not, if someone knows about it, let us know.