HLS Streaming with AVKit and SwiftUI

By the end of this article, you will be able to understand the basic of HTTP Live Streaming (HLS) and how to use it with the VideoPlayer in SwiftUI

HLS Streaming with AVKit and SwiftUI

For playing media files in apps, the AVKit framework provides all necessary components to create the necessary interfaces for media playback, transport controls, etc. It also provides a generic structure VideoPlayer for SwiftUI that displays media content with a native user interface to control playback. It is initialized with an AVPlayer object that provides the VideoPlayer with the interface to control the player’s transport behavior

AVPlayer is used to play single media files, alternatively, an AVQueuePlayer is also available to play a sequence of media items. The AVPlayer is initialized by providing either an AVPlayerItem object or by providing an URL to reference and play a single audiovisual resource.

The latter is certainly very convenient and allows a simple video player to be created in SwiftUI with just a few lines of code.

import SwiftUI
import AVKit

struct SimpleVideoPlayer: View {
    private let player = AVPlayer(url: URL(string: "YOUR-URL.mp4")
    var body: some View {
        VideoPlayer(player: player)
        .onAppear() {

Now, let's understand how to use the AVPlayer for HTTP Live Streaming. Become a free member or log in to proceed.