remoteControlReceivedWithEvent not Called in appDelegate

后端 未结 3 509
渐次进展
渐次进展 2020-12-14 07:58

I\'m having problem to control the iPhone controls with my avplayer.

if I put the function

- (void)remoteControlReceivedWithEvent:(UIEvent *)event
         


        
3条回答
  •  猫巷女王i
    2020-12-14 08:33

    I have used below code to iPhone Control -

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

    Used to get register for listening the remote control. Once done remove it -

    [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
    [self resignFirstResponder];
    

    make the App canBecomeFirstResponder-

    - (BOOL)canBecomeFirstResponder {
        return YES;
    }
    

    Used delegate method to handle iPhone control, like play and pause while doble tap on the home button

    - (void)remoteControlReceivedWithEvent:(UIEvent *)event {
        //if it is a remote control event handle it correctly
        if (event.type == UIEventTypeRemoteControl) {
            if (event.subtype == UIEventSubtypeRemoteControlPlay) {
               [audioPlayer play];
                NSLog(@"play");
            } else if (event.subtype == UIEventSubtypeRemoteControlPause) {
               [audioPlayer stop];
                 NSLog(@"pause");
            } else if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) {
                NSLog(@"toggle");
            }
        }
    }
    

    In my case i am able to handle play and pause.Please let know if any thing wrong.

提交回复
热议问题