1

I'm using AVAudioPlayer to play music

I want to control playing from remote controls which are part of using headphones.

I've already this:

override func remoteControlReceivedWithEvent(event: UIEvent?) {
        let rc = event!.subtype
        print(rc.rawValue)
        //rc.rawValue: 101 = pause, 100 = play
        switch rc {
        case .RemoteControlPlay:

            playButtonClicked("")

        case .RemoteControlPause:

            pauseButtonClicked("")

        default:break
        }

    }

It's working great from this menu

But clicks on headphones are ignored. How can I fix it?

Hreno Hrenovich
  • 336
  • 6
  • 16

1 Answers1

2

I believe that the headphones send the TogglePlayPauseCommand event:

https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPRemoteCommandCenter_Ref/index.html#//apple_ref/occ/instp/MPRemoteCommandCenter/togglePlayPauseCommand

Because I see you're using Xamarin, RemoteControlTogglePlayPause should be of interest

https://developer.xamarin.com/api/type/MonoTouch.UIKit.UIEventSubtype/

Austin
  • 1,087
  • 3
  • 14
  • 27