android - 如何在 iOS(AVFoundation 或其他第 3 方库)中使用 HLS 时移功能,如 Android 中的 ExoPlayer?

标签 android ios swift http-live-streaming

我想在 iOS 播放器中使用时移(用于直播视频)功能,但我没有找到支持时移的库。我阅读了很多像这样的图书馆的文件:

1- piemonte 2- kaltura

在Android中,google介绍ExoPlayer这很容易给我们这个功能。 我如何在 iOS 中实现此功能(通过 swift)?或者是否有任何库可以实现它?

最佳答案

试试这个:

     @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])
        }

关于android - 如何在 iOS(AVFoundation 或其他第 3 方库)中使用 HLS 时移功能,如 Android 中的 ExoPlayer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46261653/

相关文章:

java - Firestore 中 map 内的 map

ios - 如何在 swift 3 中访问计算初始化程序中的计算变量?

ios - 将数据从从 facebook 登录获取的模型类传递到 View Controller

ios - DetailViewController 上的 TabBar Controller

ios - 如何在 Swift 3 中设置 UIButton 的图像?

android - 从服务内部显示 Snackbar

Android Gradle 设置

ios - 在自定义 UIView 的 updateConstraint 函数中获取帧大小

ios - 如何在 tableViewCell 周围添加 10px 的空间?

android - 好的,类似谷歌的热词监听器