MJPEGStreamLib
简介
简单优雅的 MJPEG 流库。它基于 UIImageView,可自定义以符合您的设计。这是一次从 MjpegStreamingKit 的分支。
示例
要运行示例项目,先克隆仓库,然后从示例目录运行 pod install
要求
- iOS 8.0+
- XCode 8.1, 8.2, 8.3
- XCode 9.0+
- Swift 3.0, 3.1, 3.2
- Swift 4.0+
- Swift 4.2+
- Swift 5.0+
安装
MJPEGStreamLib可以通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中
pod "MJPEGStreamLib"
不要忘记添加外部数据网络权限
使用
import MJPEGStreamLib
一旦导入,您就可以打开与WebSocket服务器的连接。
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var loadingIndicator: UIActivityIndicatorView!
var stream: MJPEGStreamLib!
var url: URL?
override func viewDidLoad() {
super.viewDidLoad()
// Set the ImageView to the stream object
stream = MJPEGStreamLib(imageView: imageView)
// Start Loading Indicator
stream.didStartLoading = { [unowned self] in
self.loadingIndicator.startAnimating()
}
// Stop Loading Indicator
stream.didFinishLoading = { [unowned self] in
self.loadingIndicator.stopAnimating()
}
// Your stream url should be here !
let url = URL(string: "http://webcam.st-malo.com/axis-cgi/mjpg/video.cgi?")
stream.contentURL = url
stream.play() // Play the stream
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// Make the Status Bar Light/Dark Content for this View
override var preferredStatusBarStyle : UIStatusBarStyle {
return UIStatusBarStyle.lightContent
//return UIStatusBarStyle.default // Make dark again
}
}
作者
Kuray OGUN, [email protected]
许可证
MJPEGStreamLib可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。