0

I have an iOS application that streams music using RadioKit SDK. The audio plays fine while switching between different views of a tab bar controller, however when a headset is plugged in and the user is viewing one of the secondary tab views (there are 5 total, 1 primary for when the app launches, and 4 others) if they try to hit the play/pause button the app does not recognize the action. If it's playing, it won't pause, if it's paused, it won't play. The app does, however, recognize volume changes from the headset.

This behavior is consistent whether the app is in view or if in background or if the device is locked.

I've done some heavy searching and can't seem to figure this out. Help is appreciated, thank you!

iOS version 6.1.3
iOS SDK version 6.1
xCode version 4.6.3

James Gunaca
  • 13
  • 1
  • 5

1 Answers1

1

You want to listen to -(void)remoteControlReceivedWithEvent:(UIEvent *)event

Make a base UIViewController, let's call it BaseViewController and add the following :

-(void)remoteControlReceivedWithEvent:(UIEvent *)event {    

    if (event.type == UIEventTypeRemoteControl) {

        switch(event.subtype) {
            case UIEventSubtypeRemoteControlTogglePlayPause:

                break;
            case UIEventSubtypeRemoteControlPlay:

                break;
            case UIEventSubtypeRemoteControlPause:

                break;
            case UIEventSubtypeRemoteControlStop:

                break;
            default:
                break;

        }
    }
    else{
        [super remoteControlReceivedWithEvent:event];
    }
}

Also you want to include the following, in the base class, so that you can actually receive any remote control events.

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    UIApplication *application = [UIApplication sharedApplication];
    if ([application respondsToSelector:@selector(beginReceivingRemoteControlEvents)]) {
        [application beginReceivingRemoteControlEvents];
    }

    [self becomeFirstResponder];

}

And finally have all the UIViewControllers be subclass of the BaseViewController.

Dimitris
  • 403
  • 4
  • 10