Example of Android application with player and streamer

This streamer can be used to publish WebRTC video stream and play any of the following types of streams on Web Call Server

On the screenshot below the example is displayed when a stream is being published and another stream is being played.
Input fields

Two videos are played

Work with code of the example

To analyze the code, let's take class StreamingMinActivity.java of the streaming-min example version with hash 4ed4c6d77, which can be downloaded with corresponding build 1.0.1.3.

1. Initialization of the API. line 67

Flashphoner.init(this);


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

2. Connection to server.

Session for connection to server is created when Connect button is clicked. line 95

session = Flashphoner.createSession(sessionOptions);


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

Callback functions for session events are added (line 100)

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 152

session.connect(new Connection());


3. Video streaming.

New video stream is created with method Session.createStream() when Publish is clicked. line 196
Object StreamOptions (line 191) with name of the stream is passed to the method.

publishStream = session.createStream(streamOptions);


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

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


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

publishStream.publish();


4. Stop of streaming. line 234

Method Stream.stop() is called to stop video streaming when Unpublish button is clicked.

publishStream.stop();


5. Playback of video stream.

New video stream is created with method Session.createStream() when Play is clicked. line 267
Object StreamOptions (line 262) with name of the stream is passed to the method.

playStream = session.createStream(streamOptions);


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

playStream.on(new StreamStatusEvent() {
    @Override
    public void onStreamStatus(final Stream stream, final StreamStatus streamStatus) {
        .....
    }
});


Method Stream.play() is called to play the stream. line 296

playStream.play();


6. Stop of video stream playback. line 306

Method Stream.stop() is called to stop playback of video stream when Stop button is clicked.

playStream.stop();


7. Disconnection. line 164

Method Session.disconnect() is called to close connection to the server when Disconnect button is clicked.

session.disconnect();