I'm learning what https://github.com/LaiFengiOS/LFLiveKit/blob/master/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift does.
import UIKit
import LFLiveKit
class ViewController: UIViewController, LFLiveSessionDelegate {
override func viewDidLoad() {
super.viewDidLoad()
session.delegate = self
session.preView = self.view
self.requestAccessForAudio()
self.requestAccessForVideo()
self.view.backgroundColor = UIColor.clear
self.view.addSubview(containerView)
containerView.addSubview(stateLabel)
containerView.addSubview(closeButton)
containerView.addSubview(beautyButton)
containerView.addSubview(cameraButton)
containerView.addSubview(startLiveButton)
cameraButton.addTarget(self, action: #selector(didTappedCameraButton(_:)), for: .touchUpInside)
beautyButton.addTarget(self, action: #selector(didTappedBeautyButton(_:)), for: .touchUpInside)
startLiveButton.addTarget(self, action: #selector(didTappedCloseButton(_:)), for: .touchUpInside)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func requestAccessForAudio() -> Void {
let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.audio)
switch status {
case AVAuthorizationStatus.notDetermined:
AVCaptureDevice.requestAccess(for: AVMediaType.audio, completionHandler: { ( granted ) in
})
break;
case AVAuthorizationStatus.authorized: break;
case AVAuthorizationStatus.denied: break;
case AVAuthorizationStatus.restricted: break;
default:
break;
}
}
func requestAccessForVideo() -> Void {
let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.video)
switch status {
case AVAuthorizationStatus.notDetermined:
AVCaptureDevice.requestAccess(for: AVMediaType.video, completionHandler: { ( granted ) in
if (granted) {
DispatchQueue.main.async {
self.session.running = true
}
}
})
break;
case AVAuthorizationStatus.authorized:
self.session.running = true
break;
case AVAuthorizationStatus.denied: break;
case AVAuthorizationStatus.restricted: break;
default:
break;
}
}
@objc func didTappedStartLiveButton(_ button: UIButton) -> Void {
startLiveButton.isSelected = !startLiveButton.isSelected;
if (startLiveButton.isSelected) {
startLiveButton.setTitle("End Live", for: UIControl.State())
let stream = LFLiveStreamInfo()
stream.url = "rtmp://0.0.0.0:1935"
session.startLive(stream)
} else {
startLiveButton.setTitle("Start Live", for: UIControl.State())
session.stopLive()
}
}
@objc func didTappedCameraButton(_ button: UIButton) -> Void {
let devicePosition = session.captureDevicePosition;
session.captureDevicePosition = (devicePosition == AVCaptureDevice.Position.back) ? AVCaptureDevice.Position.front : AVCaptureDevice.Position.back
}
@objc func didTappedBeautyButton(_ button: UIButton) -> Void {
session.beautyFace = !session.beautyFace;
beautyButton.isSelected = !session.beautyFace
}
@objc func didTappedCloseButton(_ button: UIButton) -> Void {
// shut down
}
// Callback Functions
func liveSession(_ session: LFLiveSession?, debugInfo: LFLiveDebug?) {
print("debugInfo: \(String(describing: debugInfo?.currentBandwidth))")
}
func liveSession(_ session: LFLiveSession?, errorCode: LFLiveSocketErrorCode) {
print("errorCode: \(errorCode.rawValue)")
}
func liveSession(_ session: LFLiveSession?, liveStateDidChange state: LFLiveState) {
print("liveStateDidChange: \(state.rawValue)")
switch state {
case LFLiveState.ready:
stateLabel.text = "Not Connected"
break;
case LFLiveState.pending:
stateLabel.text = "Connecting..."
break;
case LFLiveState.start:
stateLabel.text = "Connected"
break;
case LFLiveState.error:
stateLabel.text = "Connection Error"
break;
case LFLiveState.stop:
stateLabel.text = "Not Connected"
break;
default:
break;
}
}
var session: LFLiveSession = {
let audioConfiguration = LFLiveAudioConfiguration.defaultConfiguration(for: LFLiveAudioQuality.high)
let videoConfiguration = LFLiveVideoConfiguration.defaultConfiguration(for: LFLiveVideoQuality.low3)
let session = LFLiveSession(audioConfiguration: audioConfiguration, videoConfiguration: videoConfiguration)
return session!
}()
var containerView: UIView = {
let containerView = UIView(
frame: CGRect(
origin: CGPoint(
x: 0,
y: 0
), size: CGSize(
width: UIScreen.main.bounds.width,
height: UIScreen.main.bounds.height
)
)
)
containerView.backgroundColor = UIColor.clear
containerView.autoresizingMask = [
.flexibleHeight, .flexibleHeight
]
return containerView
}()
var stateLabel: UILabel = {
let stateLabel = UILabel(
frame: CGRect(
origin: CGPoint(
x: 20,
y: 20
),
size: CGSize(
width: 80,
height: 40
)
)
)
stateLabel.text = "Not Connected"
stateLabel.textColor = UIColor.white
stateLabel.font = UIFont.systemFont(ofSize: 14)
return stateLabel
}()
var closeButton: UIButton = {
let closeButton = UIButton(
frame: CGRect(
origin: CGPoint(
x: UIScreen.main.bounds.width - 10 - 44,
y: 20
),
size: CGSize(
width: 44,
height: 44
)
)
)
closeButton.backgroundColor = UIColor.red
return closeButton
}()
var cameraButton: UIButton = {
let cameraButton = UIButton(
frame: CGRect(
origin: CGPoint(
x: UIScreen.main.bounds.width - 54 * 2,
y: 20
),
size: CGSize(
width: 44,
height: 44
)
)
)
cameraButton.backgroundColor = UIColor.blue
return cameraButton
}()
var beautyButton: UIButton = {
let beautyButton = UIButton(
frame: CGRect(
origin: CGPoint(
x: UIScreen.main.bounds.width - 54 * 3,
y: 20
),
size: CGSize(
width: 44,
height: 44
)
)
)
beautyButton.backgroundColor = UIColor.green
return beautyButton
}()
var startLiveButton: UIButton = {
let startLiveButton = UIButton(
frame: CGRect(
origin: CGPoint(
x: 30,
y: UIScreen.main.bounds.height - 50
),
size: CGSize(
width: UIScreen.main.bounds.width - 10 - 44,
height: 44
)
)
)
startLiveButton.layer.cornerRadius = 22
startLiveButton.setTitleColor(UIColor.black, for: UIControl.State())
startLiveButton.setTitle("Start Streaming", for: UIControl.State())
return startLiveButton
}()
}
This is one which I wrote, and it does not work.
AddInstanceForFactory: No factory registered for id <CFUUID 0x600001bef9c0> F8BB1C28-BAE8-11D6-9C31-00039315CD46
On launching the app, the error occurs shortly.
I had checked Swift 5.1 Error: [plugin] AddInstanceForFactory: No factory registered for id <CFUUID, but I did not use AVAudioPlayer
How can I fix it?