UITabBar中的远程控制事件用于控制播放

时间:2013-03-07 15:31:49

标签: ios objective-c cocoa-touch

这是与this类似的问题。但我仍然无法弄清楚该怎么做。

所以,我有一个tabbar应用程序,其功能类似于ipod。一个视图控制器是“NOW PLAYING”视图控制器,它是索引1处的视图控制器。因此,在VC中我有:

- (void)viewDidAppear:(BOOL)animated
{
    // Turn on remote control event delivery
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    // Set itself as the first responder
    [self becomeFirstResponder];
}

- (BOOL)canBecomeFirstResponder
{
    return YES;
}

- (void)remoteControlReceivedWithEvent:(UIEvent *)event
{
    NSLog(@"Where is my event?");
    if(event.type == UIEventTypeRemoteControl)
    {
        switch (event.subtype) {
            case UIEventSubtypeRemoteControlTogglePlayPause:
                NSLog(@"Pause");
                break;
            case UIEventSubtypeRemoteControlNextTrack:
                NSLog(@"Next");
                break;
            case UIEventSubtypeRemoteControlPreviousTrack:
                NSLog(@"Prev");
                break;
            default:
                NSLog(@"SOMETHING WAS CLICKED");
            break;

        }
    }
}

我不会在耳机或双主页按钮单击快捷方式上收到远程点击的任何事件。我在实际的iPhone上运行,而不是在模拟器中运行。我正在使用AVQueuePlayer(正在播放)来管理我的媒体。

1 个答案:

答案 0 :(得分:0)

我只是将所有内容推入AppDelegate并告诉AppDelegate调用ViewController告诉它该做什么并且它工作正常。把它放在AppDelegate中是不好的做法吗?

相关问题