Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// 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
You can’t perform that action at this time.