1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

HTTP Live Streaming再生

Last updated at Posted at 2020-02-10

先の記事テスト用のHTTP Live Streamingの環境構築の続き。

目的

今回の主目的はこちら。

  • AndroidやiOSのプレイヤーでHLSの視聴時のアクセスログを確かめたい。

前回の作業で以下はほぼ完了。

  • そのためのHLSの配信環境をmacOS上で構築する。
  • ローカルネットワークでの確認のため、CDNへの配置は行わわない。
  • macOS上のファイルストレージにHLSのファイルを書き出し、それをApacheでStreamingできるようにする。

アプリを作る(できるだけ作らない)

作るのは面倒・・・なので、

  • AndroidはExoPlayerのdemoを使う
    • media.exolist.jsonに再生したいHLSのURLを加えて完了
  • iOSは・・・AVFoundationを使ったデモを作る

iOSのデモアプリの環境

  • Xcode 11.2.1
  • 動作確認はSimulator (iOS 13.2.2を使用)

おおよその実装は[Media Playback Programming Guide

特に特別なこともしていないと思うので、説明は省略。

import UIKit
import AVKit

class AVPlayerViewExample: UIViewController {
  private var playerViewController: AVPlayerViewController!

  init() {
    super.init(nibName: nil, bundle: nil)
  }

  required init?(coder aDecoder: NSCoder) {
    fatalError("Not implemented")
  }

  override func viewDidLoad() {
    super.viewDidLoad()

    playerViewController = AVPlayerViewController()
    view.addSubview(playerViewController.view);
    let urlString = "..."
    let url: URL? = URL.init(string:urlString)
    playerViewController.player = AVPlayer(url: url!)
    playerViewController.player?.play()
  }

  override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    playerViewController.view.frame = self.view.bounds
  }

とりあえずひとまずこれで、iOSでも再生環境ができた。

あとは先日の記事で作成したHLSのストリーム http://127.0.0.1:8080/streaming/hls.m3u8 のhostをLANのIPに変えてあげれば再生できた。

今回はここまで。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?