0

因此,我正在努力允许用户从我们的应用程序开始直播(订阅者可以看到)。我们正在使用 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!)")
}
}
4

1 回答 1

1

首先,确保您下载了最新的 iOS SDK 和 Red5 Pro 服务器。 Red5 Pro 帐户网站

您的代码看起来不错,只是 iOS 代码指向您的配置的“localhost”。

config.host = Defaults.sharedDefaults.localHost

这条线试图做的是将你的 iOS 设备连接到自身。您需要将其指向您的 Red5 Pro 服务器。您应该转到您的服务器正在运行的机器,并ifconfig确定服务器的本地 IP 地址是什么或您部署服务器的 WAN IP 地址。然后将其用作 iOS 配置主机属性中的主机。

您还可以查看我们开发人员系列的“iOS 入门”部分,以了解我们如何设置类似的应用程序。https://www.red5pro.com/docs/developerseries/03/gsios.html

您还可以从帐户页面加入我们的 Slack 频道,并针对您观察到的任何问题提交工单。

希望这可以帮助!

于 2018-04-12T13:52:15.560 回答