I am playing music using AVPlayer
in Swift here is the code
let url = URL(fileURLWithPath: Bundle.main.path(forResource:chapter, ofType: nil)!)
do {
player = try AVAudioPlayer(contentsOf: url)
}
catch _ {
}
player?.prepareToPlay()
slider?.maximumValue = Float((player?.duration)!)
slider?.value = 0.0
Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.updateTime), userInfo: nil, repeats: true)
player?.play()
and using a timer along with slider to change the position of playback.
Now when the app goes to the background I want the music to continue playing and show state with MPMusicPlayerController
so that user can pause play etc from lock screen, couldnt find an example of the same or maybe my understanding is lacking.
Kindly help.