Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

Example of player for iOS

This player can be used to play any type of stream on Web Call Server

  • RTSP
  • WebRTC
  • RTMP
  • RTMFP

On the screenshot below an RTSP stream is being playing.

In the input fields

  • 192.168.2.107 in the URL is the address of the WCS server
  • stream name is entered in to the 'Play Stream' field (RTSP URL in this case)

Work with code of the example

To analyze the code, let's take Player example version with hash 9f4f5c8, which can be downloaded with corresponding build 2.2.4.

View class for the main view of the application: ViewController (header file ViewController.h; implementation file ViewController.m).

1. Import of API. ViewController.m, line 12

#import <FPWCSApi2/FPWCSApi2.h>


2. Connection to server.

ViewController method connect is called when Start button is tapped. ViewController.m, line 165

[self connect];


In the method,

- object with options for connection session is created (ViewController.m, line 30)

FPWCSApi2SessionOptions *options = [[FPWCSApi2SessionOptions alloc] init];
options.urlServer = _connectUrl.text;
options.appKey = @"defaultApp";


The options include URL of WCS server and appKey of internal server-side application.

- new session is created with method createSession (ViewController.m, line 34)

FPWCSApi2Session *session = [FPWCSApi2 createSession:options error:&error];


- callback functions for processing session statuses are added (ViewController.m, line 53)

[session on:kFPWCSSessionStatusEstablished callback:^(FPWCSApi2Session *rSession){
    [self changeConnectionStatus:[rSession getStatus]];
    [self onConnected:rSession];
}];

[session on:kFPWCSSessionStatusDisconnected callback:^(FPWCSApi2Session *rSession){
    [self changeConnectionStatus:[rSession getStatus]];
    [self onDisconnected];
}];

[session on:kFPWCSSessionStatusFailed callback:^(FPWCSApi2Session *rSession){
    [self changeConnectionStatus:[rSession getStatus]];
    [self onDisconnected];
}];


Depending on the session status, corresponding ViewController methods will be called to make appropriate changes in controls of the interface

  • if connection is successfully established: onConnected
  • in case of disconnection, or connection failure: onDisconnected

- FPWCSApi2Session method connect is called to establish connection to server (ViewController.m, line 67)

[session connect];


3. Stream playback.

When connection to the server is established, ViewController method playStream is called to start stream playback. ViewController.m, line 130

[self playStream];


In the method,

- object with stream playback options is created (ViewController.m, line 73)

FPWCSApi2StreamOptions *options = [[FPWCSApi2StreamOptions alloc] init];
options.name = _remoteStreamName.text;
options.display = _remoteDisplay;


The options include stream name and view for displaying video.

- new stream is created with FPWCSApi2Session method createStream (ViewController.m, line 77)

FPWCSApi2Stream *stream = [session createStream:options error:nil];


- callback functions for processing stream statuses are added (ViewController.m, line 95)

[stream on:kFPWCSStreamStatusPlaying callback:^(FPWCSApi2Stream *rStream){
    [self changeStreamStatus:rStream];
    [self onPlaying:rStream];
}];

[stream on:kFPWCSStreamStatusStopped callback:^(FPWCSApi2Stream *rStream){
    [self changeStreamStatus:rStream];
    [self onStopped];
}];
[stream on:kFPWCSStreamStatusFailed callback:^(FPWCSApi2Stream *rStream){
    [self changeStreamStatus:rStream];
    [self onStopped];
}];


Depending on the stream status, corresponding ViewController methods will be called to make appropriate changes in controls of the interface

  • if playback is successfully started: onPlaying
  • in case of failure, or when playback is stopped: onStopped

- FPWCSApi2Stream method play is called to play the stream (ViewController.m, line 108)

[stream play:&error]


4. Disconnection. ViewController.m, line 158

FPWCSApi2Session method disconnect is called to close connection to the server when Stop button is tapped.

[session disconnect];
  • No labels