I am following this tutorial that explain how to create an AVPlayer and use it with Swift UI. I am at the part where the seek bar becomes a progress bar for the video player.
So, following that part, I wrote the code as it's shown in the tutorial but at this following line of code,
player.addPeriodicTimeObserver(forInterval: CMTime(seconds: 0.5, preferredTimescale: 600), queue: nil) { time in
guard let item = self.player.currentItem else{
return
}
self.seekPos = time.seconds / item.duration.seconds
}
the bracket just before the time in
is underlined in red and I got the following error:
Escaping closure captures mutating 'self' parameter
Is there a way to fix this? I want that the slider becomes a video progress bar. The addPeriodicTimeObserver
is situated in an init
inside my struct
.
EDIT: The tutorial I'm using is for iOS but I'm developing for macOS. I just made the changes so the code from that tutorial works for macOS.