AVAudioPlayer can't play remote file

I'm trying to play an audio file in my SwiftUI app and first through something was wrong with the URL or file.
But even with this URL, it still gives me the following error:
Code Block
Error Domain=NSCocoaErrorDomain Code=262 "The file couldn’t be opened because the specified URL type isn’t supported."


What am I missing.
This is in a playground on Xcode 11.6

Code Block
import UIKit
import AVKit
if let url = URL(string:"https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/AudioPreview18/v4/9c/db/54/9cdb54b3-5c52-3063-b1ad-abe42955edb5/mzaf_520282131402737225.plus.aac.p.m4a")
{
var audioPlayer:AVAudioPlayer?
do {
let isReachable = try url.checkResourceIsReachable()
print(isReachable)
audioPlayer = try AVAudioPlayer(contentsOf: url)
}
catch
{
print(error)
audioPlayer = nil
}
}

Try to use AVPlayer instead.

        let urlString = "https://exampleurl.com"  // your remote url here

        guard let url = URL(string: urlString) else {return}

        let item = AVPlayerItem(url: url)

        let player = AVPlayer(playerItem: item)

        player.volume = playerVolume

        player.playImmediately(atRate: 1.0)
AVAudioPlayer can't play remote file
 
 
Q