1

In my app I have an Audio player that plays audio in background. Everything works as should be however, when I receive a call or I open another app the audio in background in my app goes silent but the remoteControlReceivedWithEvent function is not called.

My function is:

override func remoteControlReceivedWithEvent(event: UIEvent?) {

        if event!.type == UIEventType.RemoteControl {

            if event!.subtype == UIEventSubtype.RemoteControlPlay {
                //print("received remote play")
                NSNotificationCenter.defaultCenter().postNotificationName("AudioPlayerIsPlaying", object: nil)

            } else if event!.subtype == UIEventSubtype.RemoteControlPause {
                //print("received remote pause")
                NSNotificationCenter.defaultCenter().postNotificationName("AudioPlayerIsNotPlaying", object: nil)

            } else if event!.subtype == UIEventSubtype.RemoteControlNextTrack{
                //print("received next")
                nextBtn.sendActionsForControlEvents(UIControlEvents.TouchUpInside)

            }else if event!.subtype == UIEventSubtype.RemoteControlPreviousTrack{
                //print("received previus")
                backBtn.sendActionsForControlEvents(UIControlEvents.TouchUpInside)

            }else if event!.subtype == UIEventSubtype.RemoteControlTogglePlayPause{
                //print("received toggle")

                playBtn.sendActionsForControlEvents(UIControlEvents.TouchUpInside)

            }
        }
    }

How can I tell my app that a call is received or that another app has been opened?

SNos
  • 3,430
  • 5
  • 42
  • 92

0 Answers0