如何知道用户在iPhone中的播放控件上单击快进和快退按钮 [英] How can I know users click fast forward and fast rewind buttons on the playback controls in iPhone

查看:325
本文介绍了如何知道用户在iPhone中的播放控件上单击快进和快退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现以下内容:


  1. 应用正在运行音乐或视频(使用 MPMoviePlayerController )在后台。

  2. 用户双击主页按钮,转到显示播放控件的第一个屏幕(快退,播放或暂停,快进按钮)

  3. 用户点击快退或快进按钮。
    然后app播放上一个或下一个音乐或视频。

  1. App is running a music or video (using MPMoviePlayerController) in background.
  2. User double clicks the home button and go to the first screen showing playback controls (fast rewind, play or pause, fast forward buttons)
  3. User click fast rewind or fast forward button. Then app play previous or next music or video.

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

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?

推荐答案

我自己得到了答案。

那是使用UIApplication的beginReceivingRemoteControlEvents。

That is using UIApplication's beginReceivingRemoteControlEvents.

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

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

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

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

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

并且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;

这篇关于如何知道用户在iPhone中的播放控件上单击快进和快退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆