Skip to content

iOS (AVPlayer)

Example of video playback on iOS using AVPlayer

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.