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 streamer for Android

This streamer can be used to publish WebRTC video stream on Web Call Server.

On the screenshot below the example is displayed when a stream is being published.

In the URL specified in the input field

  • is the address of the WCS server
  • test is the stream name

Two videos are played

  • left - video from the camera
  • right - the published video stream as received from the server

Work with code of the example

To analyze the code, let's take class of the streamer example version with hash 4ed4c6d77, which can be downloaded with corresponding build

1. Initialization of the API. line 67


For initialization, object Сontext is passed to the init() method.

2. Connection to server.

Session for connection to server is created when Start button is clicked. line 106

session = Flashphoner.createSession(sessionOptions);

Session is created with method createSession(), to which object SessionOptions (line 99) with the following parameters is passed

  • URL of WCS server
  • SurfaceViewRenderer, which will be used to display video from the camera
  • SurfaceViewRenderer, which will be used to play the published video stream

Callback functions for session events are added (line 111)

  • onConnected() - will be called when connection is successfully established
  • onDisconnection() - will be called when connection is closed
session.on(new SessionEvent() {
    public void onConnected(final Connection connection) {
    public void onDisconnection(final Connection connection) {

Method Session.connect() is called to establish connection with WCS server. line 222

session.connect(new Connection());

3. Video streaming.

After establishing connection to the server, new video stream is created with method Session.createStream(). line 136
Object StreamOptions (line 131) with name of the stream is passed to the method.

publishStream = session.createStream(streamOptions);

Callback function for processing stream statuses is added. (line 141)

publishStream.on(new StreamStatusEvent() {
    public void onStreamStatus(final Stream stream, final StreamStatus streamStatus) {
        runOnUiThread(new Runnable() { 
            public void run() { 
                if (StreamStatus.PUBLISHING.equals(streamStatus)) {

Method Stream.publish() is called to publish the stream. line 194


4. Playback of video stream.

When the stream is published, new stream is created to play the published stream. line 158
Object StreamOptions (line 153) with name of the published stream is passed when the stream is created.

playStream = session.createStream(streamOptions);

Callback function for processing stream statuses is added. (line 163)

playStream.on(new StreamStatusEvent() {

Method is called to play the stream. line 181

playStream = session.createStream(streamOptions);

5. Disconnection. line 234

Method Session.disconnect() is called to close connection to the server.

  • No labels