I\'m using the following code to play a sound off a URL from the internet:
var audioPlayer = AVPlayer()
...
let audioSessio
You use wrong category, for AVAudioSessionCategoryAmbient it's normal behavior "Your audio is silenced by screen locking and by the Silent switch". Use AVAudioSessionCategoryPlayback instead.
AVAudioSessionCategoryAmbient
AVAudioSessionCategoryPlayback