iOS (AVPlayer)

Example of video playback on iOS using AVPlayer

Last updated Apr 21, 2026 Note

Before you can play videos, you must first upload a video to Cloudflare Stream or be actively streaming to a live input

import SwiftUI
import AVKit

struct MyView: View {
    // Change the url to the Cloudflare Stream HLS manifest URL
    private let player = AVPlayer(url: URL(string: "https://customer-9cbb9x7nxdw5hb57.cloudflarestream.com/8f92fe7d2c1c0983767649e065e691fc/manifest/video.m3u8")!)

    var body: some View {
        VideoPlayer(player: player)
            .onAppear() {
                player.play()
            }
    }
}

struct MyView_Previews: PreviewProvider {
    static var previews: some View {
        MyView()
    }
}

Download and run an example app

  1. Download this example app ↗︎ from Apple's developer docs
  2. Open and run the app using Xcode ↗︎.
  3. Search in Xcode for m3u8, and open the Streams file
  4. Replace the value of playlist_url with the HLS manifest URL for your video.

Screenshot of a video with Cloudflare watermark at top right

  1. Click the Play button in Xcode to run the app, and play your video.

For more, see read the docs.

Was this helpful?

YesNo

On this page

iOS (AVPlayer) - 图2Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/stream/examples/ios/#page","headline":"iOS (AVPlayer)","description":"Example of video playback on iOS using AVPlayer","url":"https://developers.cloudflare.com/stream/examples/ios/","inLanguage":"en","image":"https://developers.cloudflare.com/stream/examples/ios/og.png?v=2265c50f54d94888","dateModified":"2026-04-21","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["Playback"]}


description: Set up and start your first Live Stream using OBS (Open Broadcaster Software) Studio title: First Live Stream with OBS image: https://developers.cloudflare.com/stream/examples/obs-from-scratch/og.png?v=70ec8f9abf5e89ee


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/stream/llms.txt
Use this file to discover all available pages before exploring further.