Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

iOS(AVPlayer)

AVPlayer を使った iOS での動画再生の例です

最終更新 Markdown で表示Agent セットアップ
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()
    }
}

サンプルアプリをダウンロードして実行する

  1. Apple の開発者ドキュメントから このサンプルアプリ をダウンロードします
  2. Xcode でアプリを開いて実行します。
  3. Xcode で m3u8 を検索し、Streams ファイルを開きます
  4. playlist_url の値を、動画の HLS マニフェスト URL に置き換えます。
右上に Cloudflare の透かしがある動画のスクリーンショット
  1. Xcode の Play ボタンをクリックしてアプリを実行し、動画を再生します。

詳細は ドキュメント を参照してください。

役に立ちましたか?