Swift: Keep playing sounds when the device is locked

后端 未结 4 1004
眼角桃花
眼角桃花 2021-01-15 04:50

I\'m using the following code to play a sound off a URL from the internet:

var audioPlayer = AVPlayer()

...

let audioSessio         


        
4条回答
  •  无人共我
    2021-01-15 05:21

    swift 2+ solution:

    do {
      try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
      try AVAudioSession.sharedInstance().setActive(true)
    } catch _ {
      return print("error")
    }
    

提交回复
热议问题