Fast play audio files when the phone is locked

I download mp4 url ​​for video AVPlayer

and display video. But I also want the user to be able to lock their phone and keep listening to the audio video.

However, when I only download mp3 audio files, it works. Is there a way to do this the way I want with the video?

This is what I am doing:

do {
      try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: .mixWithOthers)
      try AVAudioSession.sharedInstance().setActive(true)

   } catch {
       print(error)
   }

      

In addition, the rights to my applications are owned Background Modes

and Audio, Airplay, and Picture in Picture

enabled

+3


source to share





All Articles