Justin Hodges
Justin Hodges

Reputation: 185

Getting Red5Pro Live Streaming to function properly on iOS

So I'm working on allowing users to begin a livestream (visible to those subscribed to them) from our application. We are using a Red5Pro server. I have followed the instructions from Red5's iOS page, and when it runs on the phone the camera screen comes up, our really nice looking UI comes up, everything looks great.

But when I push the button to begin recording a livestream, the app either

1) crashes abruptly

2) claims it is taking a livestream, but it won't show up on Red5's "Check if your server has a stream being broadcasted currently" page.

Anyone with Red5Pro experience wanna glance over my code and possibly point to something wrong? We are using Swift 2 still (not my choice) at the moment, and there are no error messages on Xcode's side of things. Thanks!

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!)")
}
}

Upvotes: 0

Views: 575

Answers (1)

user3411264
user3411264

Reputation: 11

First, make sure you download the latest iOS SDK and Red5 Pro server. Red5 Pro Accounts Site

Your code looks good except that you have the iOS code pointing at "localhost" for your config.

config.host = Defaults.sharedDefaults.localHost

What that line is trying to do is connect your iOS device to itself. You need to point this at your Red5 Pro server. You should go to the machine where your server is running and issue ifconfig to determine what the local IP address of the server is or the WAN IP Address where you deployed the server. Then use that as the host in your iOS config host property.

You can additionally check out the "Getting Started with iOS" section of our developer series in order to get a feel for how we set up a similar application. https://www.red5pro.com/docs/developerseries/03/gsios.html

You can also join our slack channel from the accounts page as well as submit tickets for any issues you observe.

Hope this helps!

Upvotes: 1

Related Questions