因此,我正在努力允许用户从我们的应用程序开始直播(订阅者可以看到)。我们正在使用 Red5Pro 服务器。我按照 Red5 的 iOS 页面的说明进行操作,当它在手机上运行时,相机屏幕出现,我们非常漂亮的 UI 出现了,一切看起来都很棒。
但是当我按下按钮开始录制直播时,应用程序要么
1) 突然崩溃
2) 声称它正在直播,但它不会出现在 Red5 的“检查您的服务器当前是否有正在广播的流”页面上。
任何有 Red5Pro 经验的人都想浏览我的代码并可能指出错误?我们目前仍在使用 Swift 2(不是我的选择),并且 Xcode 方面没有错误消息。谢谢!
import UIKit
import R5Streaming
class PublishViewController : R5VideoViewController, R5StreamDelegate{
var config : R5Configuration!
var stream : R5Stream!
override func viewDidLoad() {
super.viewDidLoad()
config = R5Configuration()
config.host = Defaults.sharedDefaults.localHost
config.port = Int32(Defaults.sharedDefaults.hostPort)
config.contextName = "live"
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
self.stop()
}
func preview(isBackCamera: Bool) {
let cameraDevice: AVCaptureDevice = isBackCamera ? AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo).first as! AVCaptureDevice : AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo).last as! AVCaptureDevice
let camera = R5Camera(device: cameraDevice, andBitRate: 512)
camera?.orientation = (camera?.orientation)! + 90
let audioDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio)
let microphone = R5Microphone(device: audioDevice)
let connection = R5Connection(config: config)
stream = R5Stream.init(connection: connection)
stream.attachVideo(camera)
stream.attachAudio(microphone)
stream.delegate = self
self.attachStream(stream)
self.showPreview(true)
}
func start() {
self.showPreview(false)
stream.publish("red5prostream", type:R5RecordTypeLive)
}
func stop() {
stream.stop()
stream.delegate = nil
}
func onR5StreamStatus(stream: R5Stream!, withStatus statusCode: Int32, withMessage msg: String!) {
print("Stream: \(r5_string_for_status(statusCode)) - \(msg!)")
}
}