Member-only story
VideoPlayer in SwiftUI (iOS 14 +)
iOS 14 brought AVKit to the world of SwiftUI with the introduction of VideoPlayer view. VideoPlayer displays content of an AVPlayer instance. View is defined inside AVKit framework and lets us play videos natively in SwiftUI without the need of porting functionality over from UIKit.
VideoPlayer takes player as an initialization parameter, which is an instance of AVPlayer.
Let’s start with an example. We will begin with the import of AVKit framework.
import AVKitVideos can be played from bundle or from a url. We will start by playing video from bundle.
We can download sample videos from pexels.com
https://www.pexels.com/videos/Import video and make sure that we have copy item if needed, create folder reference and add to targets checked.
Ideally, you would want to import videos in a folder, maybe create a Resources folder.
Now, all we gotta do is create VideoPlayer and AVPlayer instance to play this video.
import AVKitstruct DevTechieVideoPlayerExample: View {
var body: some View {
VStack {
Text("DevTechie")
.font(.title3)
VideoPlayer(player: AVPlayer(url…
