Enable Control Center and Lockscreen support
masterTo allow users to control playback from the Lockscreen or Control Center, you must enable remote control events in your application delegate and forward events to the AudioPlayer instance.
- In
application(_:didFinishLaunchingWithOptions:), callapplication.beginReceivingRemoteControlEvents(). - In your
UIResponder(orAppDelegate), overrideremoteControlReceivedWithEvent(_:)and pass the event to yourAudioPlayerinstance usingremoteControlReceivedWithEvent(event:).
// 1. In AppDelegate
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
application.beginReceivingRemoteControlEvents()
return true
}
// 2. In your UIResponder or AppDelegate
override func remoteControlReceivedWithEvent(event: UIEvent?) {
if let event = event {
yourPlayer.remoteControlReceivedWithEvent(event)
}
}