How to use HLS timeshifting feature in iOS(AVFoundation or other 3rd party libraries) like ExoPlayer in Android?

荒凉一梦 提交于 2020-01-06 07:07:28

问题


I want to use timeshifting (for live streaming videos) feature in iOS player,But I found no library that support timeshifting. I read documents of lots of libraries like these:

1-piemonte 2-kaltura

In Android, google introduce ExoPlayer that give us this feature easily. How can I implement this feature in iOS(by swift)? or is there any library that implement that?


回答1:


Try this:

     @IBOutlet weak var liveView: UIView! //Add `UIView` on your ViewController and create @IBOutlet for it. 
        var player = AVPlayer()
        let playerViewController = AVPlayerViewController()
        override func viewDidLoad() {
           player = AVPlayer(url: URL(string:"Your_HLS_URL")!)
           playerViewController.player = self.player
           playerViewController.player?.play()
           self.configureChildViewController(childController: self.playerViewController, onView: self.liveView)

        }

       func configureChildViewController(childController: UIViewController, onView: UIView?) {
            var holderView = self.view
            if let onView = onView {
                holderView = onView
            }
            addChildViewController(childController)
            holderView?.addSubview(childController.view)
            constrainViewEqual(holderView: holderView!, view: childController.view)
            childController.didMove(toParentViewController: self)
        }

       func constrainViewEqual(holderView: UIView, view: UIView) {
            view.translatesAutoresizingMaskIntoConstraints = false
            //pin 100 points from the top of the super
            let pinTop = NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal,
                                            toItem: holderView, attribute: .top, multiplier: 1.0, constant: 0)
            let pinBottom = NSLayoutConstraint(item: view, attribute: .bottom, relatedBy: .equal,
                                               toItem: holderView, attribute: .bottom, multiplier: 1.0, constant: 0)
            let pinLeft = NSLayoutConstraint(item: view, attribute: .left, relatedBy: .equal,
                                             toItem: holderView, attribute: .left, multiplier: 1.0, constant: 0)
            let pinRight = NSLayoutConstraint(item: view, attribute: .right, relatedBy: .equal,
                                              toItem: holderView, attribute: .right, multiplier: 1.0, constant: 0)

            holderView.addConstraints([pinTop, pinBottom, pinLeft, pinRight])
        }


来源:https://stackoverflow.com/questions/46261653/how-to-use-hls-timeshifting-feature-in-iosavfoundation-or-other-3rd-party-libra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!