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:
import SwiftUI
import AVKit
struct VideoView: View {
private let player = AVPlayer(url: URL(string: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8")!)
var body: some View {
VideoPlayer(player: player)
}
}
But beware! This apparently works fine on a device running the iOS 14 beta, but the simulator has big issues with video playback now, across all AVPlayer scenarios.
VideoPlayer effectively gives you an AVPlayerViewController embedded in your view hierarchy, so you get Apple’s default controls and behaviours for free.
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.
#xcode #ios-app-development #ios #swiftui #swift