MJPEGStreamLib
MJPEGStreamLib copied to clipboard
Simple and easy to use MJPEG Stream Library. It contains authentication if your stream url needs a username/password. It is based on UIImageView so it is all up to your custom design.
MJPEGStreamLib
Introduction
Simple and elegant MJPEG Stream library. It is based on UIImageView and customizeable for your design. This is original a fork from MjpegStreamingKit
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Requirements
- 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+
Installation
MJPEGStreamLib is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "MJPEGStreamLib"
DO NOT FORGET TO ADD PERMISSION FOR EXTERNAL DATA NETWORK :
Usage
import MJPEGStreamLib
Once imported, you can open a connection to your WebSocket server.
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
}
}
Author
Kuray OGUN, [email protected]
License
MJPEGStreamLib is available under the MIT license. See the LICENSE file for more info.