0

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.

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159
vishal dharankar
  • 7,536
  • 7
  • 57
  • 93

1 Answers1

0

Try MPNowPlayingInfoCenter class for seting now playing info on the lock screen and MPRemoteCommandCenter class for commands available to control playback from lock screen.

Vikas Dadheech
  • 1,672
  • 12
  • 23