1

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"
                )!
            )
        )
    }
Tamás Horváth
  • 219
  • 2
  • 8
  • 1
    You may start from here: https://stackoverflow.com/questions/60480652/struggling-with-notificationcenter-combine-in-swiftui-avplayer – olha Oct 25 '21 at 08:06
  • Thanks, I've checked that already, that's only a solution for the case when the video ends by it's own because it has finished. I could also cover that case with `AVPlayerItemDidPlayToEndTime`, but still no clue how to handle the cases when the user stops it or changes the slider – Tamás Horváth Oct 25 '21 at 17:45

0 Answers0