I am testing this using iOS 10.2 on my iPhone 6s device itself.
I play streaming audio and can play / pause sound, skip tracks, etc. I also turned on the background modes, and the sound plays in the background and continues through the playlist correctly. The only problem I encountered is getting the screen lock controls to display. Nothing is displayed at all ...
In the viewDidLoad () of my MainViewController, right after starting my application, I call it ...
func setupAudioSession(){
UIApplication.shared.beginReceivingRemoteControlEvents()
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: AVAudioSessionCategoryOptions.mixWithOthers)
self.becomeFirstResponder()
do {
try AVAudioSession.sharedInstance().setActive(true)
print("AVAudioSession is Active")
} catch let error as NSError {
print(error.localizedDescription)
}
} catch let error as NSError {
print(error.localizedDescription)
}
}
and then in my AudioPlayer class after starting to play the sound I call ...
func setupLockScreen(){
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.nextTrackCommand.isEnabled = true
commandCenter.nextTrackCommand.addTarget(self, action:#selector(skipTrack))
MPNowPlayingInfoCenter.default().nowPlayingInfo = [MPMediaItemPropertyTitle: "TESTING"]
}
iPhone , , . , . , ( , , ).
, AVAudioPlayer AVPlayer? , , , Spotify , ? /