AVPlayer & SwiftUI Part 5: VideoPlayer is here!

Chris Mash
2 min readJun 25, 2020

Note: video playback on the simulator seems to not show the video, just play the audio, so use a real device if necessary!

This blog is related to the SwiftUI video player that’s been progressing over part 1, part 2, part 3 and part 4. But don’t worry! You don’t need to catch up!

WWDC20 and the arrival of the iOS 14 beta has revealed a new View for SwiftUI: VideoPlayer! And look how simple it is to use:

VideoPlayer effectively gives you an AVPlayerViewController embedded in your view hierarchy, so you get Apple’s default controls and behaviours for free.

But beware! If you don’t start the player playing programmatically then your VideoPlayer won’t show any controls, so you can’t start it going!

My GitHub repo has been updated to provide a working example.

While you can provide an overlay view (which sits between the video and the controls) it doesn’t seem like you can disable the default controls. If you want to apply custom controls, or even just hide the defaults then you probably still need to go the old route laid out in parts 1–4 of this blog series, so there’s still some value there!

WWDC20 has brought lots of nice improvements to SwiftUI, many of them nicely summarised by Paul Hudson over at Hacking With Swift.

--

--

Chris Mash

iOS developer since 2012, previously console games developer at Sony and Activision. Twitter: @CJMash