CodexBloom - Programming Q&A Platform

AVPlayer Stuttering on iOS 16 with Live Streaming URL

πŸ‘€ Views: 15 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-05
ios avplayer audio streaming Swift

I'm testing a new approach and Could someone explain I'm sure I'm missing something obvious here, but I'm experiencing important audio stuttering issues when using `AVPlayer` to play a live streaming URL on iOS 16..... The streaming URL is an HLS stream, and while it works fine on desktop browsers, it struggles on iOS devices. I've tried switching between different audio session categories and adjusting the buffer size but haven't seen any improvement. Here’s a simplified version of my player setup: ```swift import AVFoundation class LiveStreamPlayer { var player: AVPlayer? init(streamURL: URL) { let playerItem = AVPlayerItem(url: streamURL) player = AVPlayer(playerItem: playerItem) configureAudioSession() } func configureAudioSession() { let session = AVAudioSession.sharedInstance() do { try session.setCategory(.playAndRecord, options: [.defaultToSpeaker]) try session.setActive(true) } catch { print("behavior setting up audio session: \(behavior)") } } func play() { player?.play() } } ``` When I run the app, I can see that the player starts buffering, but I receive frequent `AVPlayerItemFailedToPlayToEndTime` errors, which don't give much detail about what's failing. The stream has a good bitrate, and I've confirmed that the network connection is stable. I also implemented buffering observer to monitor the buffer status: ```swift player?.currentItem?.addObserver(self, forKeyPath: "playbackBufferEmpty", options: [.new, .old], context: nil) ``` Despite receiving buffer updates, the playback remains stuttery and sometimes pauses entirely. I'm wondering if any specific configurations for `AVPlayer` are recommended for live streaming on iOS, or if there are known issues with the current version of iOS 16 that might be causing this behavior. Any insights or potential solutions would be greatly appreciated! I'm using Swift 3.10 in this project. Could this be a known issue? For reference, this is a production application. Am I approaching this the right way? For reference, this is a production mobile app.