This example shows how to easily subscribe to a Red5 Pro stream.
Subscribing to a Red5 Pro stream requires a few components to function fully.
The R5Connection manages the connection that the stream utilizes. You will need to setup a configuration and intialize a new connection.
func getConfig()->R5Configuration{
// Set up the configuration
let config = R5Configuration()
config.host = Testbed.getParameter("host") as! String
config.port = Int32(Testbed.getParameter("port") as! Int)
config.contextName = Testbed.getParameter("context") as! String
config.`protocol` = 1;
config.buffer_time = Testbed.getParameter("buffer_time") as! Float
return config
}
let config = getConfig()
// Set up the connection and stream
let connection = R5Connection(config: config)
The R5Stream
handles both subscribing and publishing. Creating one simply requires the connection already created.
//Create our new stream that will utilize that connection
self.publishStream = R5Stream(connection: connection)
//Setup our listener to handle events from this stream
self.publishStream!.delegate = self
The R5StreamDelegate
that is assigned to the R5Stream
will receive status events for that stream, including connecting, disconnecting, and errors.
The R5VideoViewController
will present publishing streams as well as subscribed streams. To view the subscribing stream, it simply needs to attach the R5Stream
.
A R5VideoViewController
can be set on any UIViewController, or created programmatically
let r5View : R5VideoViewController = getNewR5VideoViewController(self.view.frame);
self.addChildViewController(r5View);
To view the preview before publishing has started, use R5VideoViewController.showPreview
.
view.addSubview(r5View.view)
r5View.showPreview(true)
r5View.showDebugInfo(true)
Lastly, we attach the Stream to the R5VideoView to see the streaming content.
currentView?.attachStream(subscribeStream)
The R5Stream.Subscribe
method will establish the server connection and begin Subscribing.
self.subscribeStream!.play(Testbed.getParameter("stream1") as! String)