I want to create a VideoPlayer
in SwiftUI, but I want to react to events like:
- user starts the video
- user stops the video
- user drags the slider
Is it possible somehow? All I found was one defualt event in NotificationCenter
, but called AVPlayerItemDidPlayToEndTime
. I also searched here and everyone recommends to observe the rate
property of AVPlayer
, but that's not good for me, as I can't distinguish if the user stopped playing the video, or just drags the slider. Does anyone have a solution for this?
VideoPlayer
is a built-in element, basically with this code it works:
var body: some View {
VideoPlayer(
player: AVPlayer(
url: URL(string: "https://vid.tasty.co/output/217191/hls24_1632510042.m3u8"
)!
)
)
}