如何在iOS(AVFoundation或其他第三方库)中使用HLS时移功能,例如Android中的ExoPlayer? [英] How to use HLS timeshifting feature in iOS(AVFoundation or other 3rd party libraries) like ExoPlayer in Android?
本文介绍了如何在iOS(AVFoundation或其他第三方库)中使用HLS时移功能,例如Android中的ExoPlayer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在iOS播放器中使用时移(用于实时流式传输视频)功能,但是我没有找到支持时移的库.我阅读了许多类似这样的图书馆的文件:
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:
在Android中,Google引入了 ExoPlayer ,可轻松为我们提供此功能. 如何在iOS中实现此功能(通过Swift)?还是有实现该功能的库?
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?
推荐答案
尝试一下:
@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])
}
这篇关于如何在iOS(AVFoundation或其他第三方库)中使用HLS时移功能,例如Android中的ExoPlayer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文