Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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)

Image Added

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

Code Block
languagejs
themeRDark
#import <FPWCSApi2/FPWCSApi2.h>


2. Connection to server.

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

Code Block
languagejs
themeRDark
[self connect];


In the method,

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

Code Block
languagejs
themeRDark
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)

Code Block
languagejs
themeRDark
FPWCSApi2Session *session = [FPWCSApi2 createSession:options error:&error];


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

Code Block
languagejs
themeRDark
[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)

Code Block
languagejs
themeRDark
[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

Code Block
languagejs
themeRDark
[self playStream];


In the method,

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

Code Block
languagejs
themeRDark
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)

Code Block
languagejs
themeRDark
FPWCSApi2Stream *stream = [session createStream:options error:nil];


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

Code Block
languagejs
themeRDark
[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)

Code Block
languagejs
themeRDark
[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.

Code Block
languagejs
themeRDark
[session disconnect];