AVPlayer not seeking accurately in iOS 17 when using custom buffering logic
I've been researching this but I'm building a feature where I'm experiencing an scenario with AVPlayer in my iOS 17 app where seeking to a specific time doesn't work as expected when using a custom buffering strategy... I have implemented a custom AVAssetResourceLoaderDelegate to manage asset loading, and I am manually buffering segments of the media. However, when I try to seek to a specific time, it seems to seek to the wrong location, or the playback starts stuttering after the seek. Hereβs how I set up the player and the resource loader: ```swift let playerItem = AVPlayerItem(url: mediaURL) let player = AVPlayer(playerItem: playerItem) player.currentItem?.addObserver(self, forKeyPath: "status", options: [.old, .new], context: nil) let resourceLoader = AVAssetResourceLoader() resourceLoader.setDelegate(self, for: .asset) playerItem.asset.resourceLoader = resourceLoader ``` And hereβs how I handle the seek operation: ```swift func seek(to time: CMTime) { player.seek(to: time) { [weak self] completed in if completed { print("Seek to \(time) completed") } else { print("Seek to \(time) failed") } } } ``` I've noticed that when I log the current time after seeking, it sometimes returns a value that's several seconds off from what I expected. Additionally, I'm not seeing any errors in the console, but the playback stutters and I occasionally receive an behavior: `AVError.codeFileNotFound` when I attempt to load segments that should already be buffered. I've tried adjusting my buffer settings and ensuring that the resource loader is fetching data correctly, but the scenario continues. Is there a known scenario with AVPlayer seeking behavior when using a custom resource loader in iOS 17, or could there be something wrong with how I'm managing the buffering? Any insights would be greatly appreciated! Is there a simpler solution I'm overlooking? This is part of a larger service I'm building. What's the correct way to implement this?