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
Uislider That Snaps to a Fixed Number of Steps (Like Text Size in the iOS 7 Settings App)
Uikeyboardboundsuserinfokey Is Deprecated, What to Use Instead
Back Button Callback in Navigationcontroller in iOS
How to Add Older Version of iOS Sdk in Xcode 4.5
What Exactly Is Init Coder Adecoder
Access Files in /Var/Mobile/Containers/Data/Application Without Jailbreaking Iphone
iPhone Sdk Internet Connection Detection
How to Scale a Uibutton's Imageview
How to Get Hour and Minutes from Nsdate
Contentview Not Indenting in iOS 6 Uitableviewcell Prototype Cell
Mfmailcomposeviewcontroller in iOS 7 Statusbar Are Black
Xcode Cannot Run on the Selected Destination
@Property/@Synthesize Equivalent in Swift
Found an Unexpected MACh-O Header Code: 1918975009 in Xcode 6
How to Calculate the Uilabel Height Dynamically
iOS - Swift - Function That Returns Asynchronously Retrieved Value