Switching between HLS streams with AVKit
With this tutorial you will be able to create a simple VideoPlayerViewModel that monitors the playback buffer of an AVPlayerItem and lowered resolution of the playback is likely to stall.
Recently, we explored HLS Streaming with AVKit and SwiftUI and how we can leverage different
.m3u8 manifest files for media playlists. With that approach, videos can be made available in different resolutions and bandwidths to accommodate a variety of network conditions.
Even though HLS support intelligent detection of available bandwidth out of the box, sometimes it might be interesting to dig a little deeper and provide mechanisms to switch bandwidth based on user input as well as on our own estimation of the networking conditions.
One way to do that is by monitoring the buffer of the AVPlayer's current AVPlayerItem. The class provides multiple properties to determine the buffering status:
Most relevantly, isPlaybackBufferEmpty indicates whether all buffered media is consumed and that playback will stop, and isPlaybackLikelyToKeepUp indicates whether the item will play through without stalling.
Let's explore how that could work. Become a free member or log in to proceed.