How to Know Users Click Fast Forward and Fast Rewind Buttons on the Playback Controls in Iphone

How can I know users click fast forward and fast rewind buttons on the playback controls in iPhone

I got the answer by myself.

That is using UIApplication's beginReceivingRemoteControlEvents.

In an appropriate place (like viewWillAppear:) put the following code

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];

And the view controller should implement the following method returning YES

- (BOOL)canBecomeFirstResponder {
return YES;
}

And then you can receive remote controller event in the following method.

- (void)remoteControlReceivedWithEvent:(UIEvent *)event {

if( event.type == UIEventTypeRemoteControl ) {
NSLog(@"sub type: %d", event.subtype);
}
}

And event.subtype is as below,

typedef enum {
// available in iPhone OS 3.0
UIEventSubtypeNone = 0,

// for UIEventTypeMotion, available in iPhone OS 3.0
UIEventSubtypeMotionShake = 1,

// for UIEventTypeRemoteControl, available in iPhone OS 4.0
UIEventSubtypeRemoteControlPlay = 100,
UIEventSubtypeRemoteControlPause = 101,
UIEventSubtypeRemoteControlStop = 102,
UIEventSubtypeRemoteControlTogglePlayPause = 103,
UIEventSubtypeRemoteControlNextTrack = 104,
UIEventSubtypeRemoteControlPreviousTrack = 105,
UIEventSubtypeRemoteControlBeginSeekingBackward = 106,
UIEventSubtypeRemoteControlEndSeekingBackward = 107,
UIEventSubtypeRemoteControlBeginSeekingForward = 108,
UIEventSubtypeRemoteControlEndSeekingForward = 109,
} UIEventSubtype;

Fast Rewind & Fast Forward in AVAudioPlayer

One possible solution is to implement the repeating action by an NSTimer. Have a look at UIButton Touch and Hold.

Background audio controls: 15 second forward/rewind as in AudioBooks

You can't (yet)

That's an Apple-only thing, currently only available for their apps - specifically the Music and Podcasts apps.

However, iOS 7 should be introduced within a few months - watch for this functionality to be introduced in the next release.

MPMoviePlayerController and next button

I found a way, see my question and answer.

How can I know users click fast forward and fast rewind buttons on the playback controls in iPhone

How do I catch the MPMoviePlayer next button click event while in fullscreen mode on the iPad?

Here's another possibility I just stumbled across. The MPMoviePlayerController in full-screen mode may be sending Remote Control events. Catch these (iOS 4 only, by the way) by enabling remote control event messages in your view controller:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];

and then implement

[UIResponder remoteControlReceivedWithEvent:(UIEvent*)event];

and when the view goes away, unregister in viewWillDisappear:

[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];

I'm not certain that this will work, but it's worth a shot.

Next/Previous buttons on iPhone MPMoviePlayerController

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


Related Topics



Leave a reply



Submit