I’ve created a very simple AVPlayer within a macOS app.
import Cocoa
import AVKit
import AVFoundation
class ViewController: NSViewController {
@IBOutlet var playerView: AVPlayerView!
override func viewDidLoad() {
super.viewDidLoad()
let videoPath = URL(fileURLWithPath: "myPath/myFile.mp4")
let videoPlayer = AVPlayer(url: videoPath)
playerView.player = videoPlayer
}
}
It basically works fine, but the player plays automatically on launch, which it should not. Even when I add playerView.player?.pause()
at the end of viewDidLoad
, it autoplays.
What am I doing wrong?