How do you attach/play an audio file and player in Swift Playgrounds?

I know it works in Xcode however, I want to create it specifically in the "Answers" template on Swift Playgrounds. Will the code still work on the template or does attaching an audio player and file only work on a new, blank Playground?

Same here,


I have this code which I found on the internet, but it doesn't seem to work on the Playgrounds


import AVFoundation
import PlaygroundSupport
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
let width = 568
let height = 320
let container = UIView(frame: CGRect(x: 0, y: 0, width: width, height: height))
PlaygroundPage.current.liveView = container
PlaygroundPage.current.needsIndefiniteExecution = true
func playVideo(_ url: URL){
    let f=CGRect(x: 0, y: 0, width: width, height: height)
    let playerItem = AVPlayerItem(url: url)
   
    let player=AVPlayer(playerItem: playerItem)
    let playerLayer=AVPlayerLayer(player: player)
   
    playerLayer.frame=f
    container.layer.addSublayer(playerLayer)
    PlaygroundPage.current.liveView = container
   
    player.play()
}
playVideo(URL(string:"http://s3.amazonaws.com/vids4project/sample.mp4")!)
See my answer here. I have both a SwiftUI and UIKit solution.
How do you attach/play an audio file and player in Swift Playgrounds?
 
 
Q