New Video Player In SwiftUI

Since iOS 14 and the second version of SwiftUI, there is a new ViewPlayer.

To use it, you need to import AVKit at first.

import AVKit

Next, create a VideoPlayer view with AVPlayer as a parameter.

VideoPlayer(player: AVPlayer(url: URL(string: “https://smashswift.com/video”)!))

It doesn’t work on the simulator, if you want to watch it you need to run it on a physical device.

There is a second optional parameter inside VideoPlayer, it’s overlay.

VideoPlayer(player: AVPlayer(url: URL(string: “https://smashswift.com/video”)!)) {
   Text(“Overlay”)
   
   .font(.largeTitle)
}