Subscriber View Controller
1 Drag a View Controller from the Object Library and drop it into the storyboard alongside the Second View Controller
2 With the View Controller selected, focus on the Identity Inspector and change the Custom Class field to SubcribeViewController
3 Still within the Identity Inspector for the View Controller, assign a Storyboard ID of subscribeView
4 From the Project Explorer Right-Click on the Red5ProStreaming folder and select New File…
5 Choose Object-C class from the wizard dialog and Next
6 In the Class field, set SubscribeViewController
and choose R5VideoViewController
for Subclass of field
7 Select Next and add to project at current location.
8 Open the SubcribeViewController.h header and add start
and stop
methods to the interface
@interface SubscribeViewController : R5VideoViewController
-(void)start;
-(void)stop;
@end
9 Open the SubscribeViewController.m, import the R5Streaming header and header and add variables to the internal interface for an R5Configuration and R5Stream instance:
#import "SubscribeViewController.h"
#import <R5Streaming/R5Streaming.h>
@interface SubscribeViewController () {
R5Configuration *config;
R5Stream *stream;
}
@end
10 In the viewDidLoad
override in SubscribeViewController.m, create the R5Configuration that will be used in a streaming session(s).
- Change the host attribute to point to the location of your Red5 Pro server.
- _Change the SDK license key to the one provided from your Red5 Pro Account._
- (void)viewDidLoad {
[super viewDidLoad];
config = [R5Configuration new];
config.host = @"localhost";
config.port = 8554;
config.contextName = @"live";
config.licenseKey = @"YOUR-SDK-LICENSE-KEY";
}
11 The two methods added to the SubscribeViewController.h interface — start
and stop
— are all that will be needed to implement in order to interface with the Subscriber
- (void)start {
R5Connection *connection = [[R5Connection new] initWithConfig:config];
stream = [[R5Stream new] initWithConnection:connection];
[self attachStream:stream];
[stream play:@"red5prostream"];
}
- (void)stop {
[stream stop];
}
12 Note the NSString passed into the stream:play:
method, this to the publish stream name appropriately.
These are the methods we defined on the interface for SubscribeViewController previously and will be invoked externally by UI controls in the app.
13 Override the viewWillDisappear:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self stop];
}
That completes the SubscribeViewController implementation that be used and interfaced with from the SecondViewController.