Skip to content

Instantly share code, notes, and snippets.

@mwawrusch
Last active June 9, 2017 20:19
Show Gist options
  • Save mwawrusch/3f945b6487540bb890a363b36ae580cc to your computer and use it in GitHub Desktop.
Save mwawrusch/3f945b6487540bb890a363b36ae580cc to your computer and use it in GitHub Desktop.
//
// ViewController.swift
// TestLive
//
// Created by Martin Wawrusch on 6/9/17.
//
import UIKit
import lf
import AVFoundation
class XXViewController: UIViewController {
let rtmpConnection = RTMPConnection()
var rtmpStream:RTMPStream!
@IBOutlet weak var lfView: LFView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
lfView.videoGravity = AVLayerVideoGravityResizeAspectFill
rtmpStream = RTMPStream(connection: rtmpConnection)
rtmpStream.syncOrientation = true
/*
rtmpStream.captureSettings = [
"sessionPreset": AVCaptureSessionPreset1280x720,
"continuousAutofocus": true,
"continuousExposure": true,
]
rtmpStream.videoSettings = [
"height": 1280,
"width": 720,
]
rtmpStream.audioSettings = [
"sampleRate": 44_100
]
*/
rtmpConnection.addEventListener(Event.RTMP_STATUS, selector:#selector(XXViewController.rtmpStatusHandler(_:)), observer: self)
rtmpConnection.connect("rtmp://YYYY.entrypoint.cloud.wowza.com:1935/app-ZZZZ")
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
rtmpStream.attachAudio(AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio)) { error in
print(error)
}
rtmpStream.attachCamera(DeviceUtil.device(withPosition: .front)) { error in
print(error)
}
lfView.attachStream(rtmpStream)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
rtmpStream.close()
rtmpStream.dispose()
}
func rtmpStatusHandler(_ notification:Notification) {
let e:Event = Event.from(notification)
if let data:ASObject = e.data as? ASObject , let code:String = data["code"] as? String {
print("---------")
print(code)
print("=========")
switch code {
case RTMPConnection.Code.connectSuccess.rawValue:
self.rtmpStream.publish("XXXXX")
// sharedObject!.connect(rtmpConnection)
default:
break
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment