CodexBloom - Programming Q&A Platform

AVPlayer buffering implementing HLS streams in iOS 17 causing stutter and delays

๐Ÿ‘€ Views: 53 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-07-16
iOS AVPlayer HLS buffering Swift

I've tried everything I can think of but I've looked through the documentation and I'm still confused about I'm experiencing important buffering issues when using AVPlayer to stream HLS video content in my iOS 17 app..... The videos often stutter or unexpected result to play altogether after a few seconds, especially on slower network connections. I've set the `automaticallyWaitsToMinimizeStalling` property to `false` in an attempt to handle playback behavior, but it hasn't resolved the scenario. Hereโ€™s a snippet of how Iโ€™m setting up the player: ```swift let url = URL(string: "https://example.com/stream.m3u8")! let playerItem = AVPlayerItem(url: url) let player = AVPlayer(playerItem: playerItem) player.automaticallyWaitsToMinimizeStalling = false let playerLayer = AVPlayerLayer(player: player) playerLayer.frame = self.view.bounds self.view.layer.addSublayer(playerLayer) player.play() ``` I've also tried using the `AVPlayerItem`'s `preferredForwardBufferDuration` property to see if increasing the buffer size helps, but that hasnโ€™t yielded any improvement either: ```swift playerItem.preferredForwardBufferDuration = 60 ``` Iโ€™ve checked the network speed and ensured itโ€™s not affecting the playback, but I still encounter buffering after the initial play starts. Has anyone faced similar issues or have suggestions on how to mitigate this buffering question? Any insights on configuration or AVPlayer best practices with HLS streams in iOS 17 would be greatly appreciated. My development environment is macOS. Is there a better approach? I'm working on a application that needs to handle this. Is there a better approach? I'm working in a Ubuntu 20.04 environment. What am I doing wrong? How would you solve this?