因此,我正在努力允许用户从我们的应用程序开始一个实况流(对订阅者可见)。我们使用的是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!)")
}
}发布于 2018-04-12 21:52:16
首先,确保下载最新的iOS软件开发工具包和Red5专业版服务器。Red5 Pro Accounts Site
您的代码看起来不错,除了您的配置中iOS代码指向"localhost“。
config.host = Defaults.sharedDefaults.localHost
这行代码要做的就是将你的iOS设备连接到它自己。你需要把这个指向你的Red5专业版服务器。您应该转到运行服务器的计算机并发出ifconfig命令,以确定服务器的本地IP地址或部署服务器的WAN地址。然后在您的iOS配置主机属性中使用它作为主机。
您还可以查看我们的开发人员系列的“iOS入门”部分,以了解我们如何设置类似的应用程序。https://www.red5pro.com/docs/developerseries/03/gsios.html
您还可以从帐户页面加入我们的松弛频道,并为您观察到的任何问题提交工单。
希望这能有所帮助!
https://stackoverflow.com/questions/42149406
复制相似问题