ios – 如何知道用户在iPhone中的播放控件上单击快进和快退按钮

前端之家收集整理的这篇文章主要介绍了ios – 如何知道用户在iPhone中的播放控件上单击快进和快退按钮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想实现以下内容,

> App正在后台运行音乐或视频(使用MPMoviePlayerController).
>用户双击主页按钮并转到显示播放控件的第一个屏幕(快退,播放或暂停,快进按钮)
>用户单击快退或快进按钮.
然后应用播放上一个或下一个音乐或视频.

对于第3步,我应该知道单击了哪个按钮.
(我自然知道,当前播放的项目已暂停,停止使用MPMoviePlayerPlaybackStateDidChangeNotification通知).

我应该注册哪个通知?还是有其他方法吗?

解决方法

我自己得到了答案.

那是使用UIApplication的beginReceivingRemoteControlEvents.

在适当的地方(如viewWillAppear :)放入以下代码

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

并且视图控制器应该实现以下方法返回YES

@H_301_20@- (BOOL)canBecomeFirstResponder { return YES; }

然后您可以通过以下方法接收远程控制器事件.

@H_301_20@- (void)remoteControlReceivedWithEvent:(UIEvent *)event { if( event.type == UIEventTypeRemoteControl ) { NSLog(@"sub type: %d",event.subtype); } }

event.subtype如下,

@H_301_20@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;

猜你在找的iOS相关文章