Implementation of HTTP Live Streaming in iOS

前端 未结 3 1743
长情又很酷
长情又很酷 2020-12-22 15:18

I want to write a little iOS video client and have to use HTTP Live Streaming. The videos come from a Wowza Media Server which supports HTTP Live Streaming, so the server-si

3条回答
  •  一个人的身影
    2020-12-22 16:05

    Below is my Swift 4 solution with AVPlayer

    [since MPMoviePlayerController is deprecated in iOS 9]

    import UIKit
    import AVKit
    ...
    
    class VideoPlayerViewController: UIViewController {
    
        var player: AVPlayer?
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            guard let url = URL(string: "http://stream-url.com/file.m3u8") else {
                print("Umm, looks like an invalid URL!")
                return
            }
    
            player = AVPlayer(url: url)
            let controller = AVPlayerViewController()
            controller.delegate = self
            controller.player = player
    
            // present the player controller & play
            present(controller, animated: true) {
                self.player?.play()
            }
        }
    
    }
    

提交回复
热议问题