AVAudio中的remoteControlReceivedWithEvent未被调用 [英] remoteControlReceivedWithEvent in AVAudio is not being called

查看:130
本文介绍了AVAudio中的remoteControlReceivedWithEvent未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在后台播放音频的应用。我按照app docs的指示编写了iPod控件的代码。我实现了这个

I am working on an app playing the audio in background. I have written the code for the iPod controls as directed by app docs. I have implemented this like

- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {    
    if (receivedEvent.type == UIEventTypeRemoteControl) {

        switch (receivedEvent.subtype) {

            case UIEventSubtypeRemoteControlTogglePlayPause:
                [self playButtonPressed:playButton];
                [self testing];
                break;

            case UIEventSubtypeRemoteControlPreviousTrack:
                [self rewButtonReleased:(UIButton *)rewButton];
                break;

            case UIEventSubtypeRemoteControlNextTrack:
                [self ffwButtonReleased:(UIButton *)ffwButton];
                break;

            default:
                break;
        }
    }
}
- (BOOL)canBecomeFirstResponder {
    NSLog(@"canBecomeFirstResponder");
    return YES;
}

- (void) viewDidAppear:(BOOL)animated 
{
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(beginReceivingRemoteControlEvents)]){
        [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
        [self becomeFirstResponder];
    }
}

- (void) viewWillDisappear:(BOOL)animated 
{
    [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
    [self resignFirstResponder];
}

请告诉我我还需要什么或在哪里犯任何错误。问候!

Please suggest me what else do I need or where am I committing any mistakes. Regards!

推荐答案

确保它可以成为第一响应者

Just make sure it can become first responder

- (BOOL)canBecomeFirstResponder {
     return YES;
}

这篇关于AVAudio中的remoteControlReceivedWithEvent未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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