Table of Contents |
---|
Overview
WCS provides SDK to develop client applications for the Android platform
Operation flowchart
- The browser connects to the server via the Websocket protocol and sends the publish command.
- The browser captures the microphone and the camera and sends the WebRTC stream to the server.
- The Android device connects to the server via the Websocket protocol and sends the play command.
- The Android device receives the WebRTC stream from the server and plays it in the application.
Quick manual on testing
Playing a video stream in an Android mobile application
1. For the test we use:
- the demo server at demo.flashphoner.com;
- the Two Way Streaming web application to publish the stream;
- the Player mobile application (Google Play) to play the stream
2. Open the Two Way Streaming web application. Click Connect, then Publish. Copy the identifier of the stream:
3. Install on the Android device the Player mobile app from Google Play. Start the app on the device, and in the "WCS url" field enter the address of the WCS server as wss://demo.flashphoner.com:8443, in the "Play Stream" field - the identifier of the video stream:
4. Click Start. The video stream starts playing.
Call flow
Below is the call flow when using the Player example to play the stream.
1. Establishing a connection to the server.
Flashphoner.createSession(); code
Code Block | ||||
---|---|---|---|---|
| ||||
/**
* The options for connection session are set.
* WCS server URL is passed when SessionOptions object is created.
* SurfaceViewRenderer to be used to display the video stream is set with method SessionOptions.setRemoteRenderer().
*/
SessionOptions sessionOptions = new SessionOptions(mWcsUrlView.getText().toString());
sessionOptions.setRemoteRenderer(remoteRender);
/**
* Session for connection to WCS server is created with method createSession().
*/
session = Flashphoner.createSession(sessionOptions); |
2. Receiving from the server an event that confirms successful connection.
ConnectionStatusEvent ESTABLISHED code
Code Block | ||||
---|---|---|---|---|
| ||||
@Override
public void onConnected(final Connection connection) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mStartButton.setText(R.string.action_stop);
mStartButton.setTag(R.string.action_stop);
mStartButton.setEnabled(true);
mStatusView.setText(connection.getStatus());
/**
* The options for the stream to play are set.
* The stream name is passed when StreamOptions object is created.
*/
StreamOptions streamOptions = new StreamOptions(mPlayStreamView.getText().toString());
/**
* Stream is created with method Session.createStream().
*/
playStream = session.createStream(streamOptions); |
3. Playing the stream.
stream.play(); code
Code Block | ||||
---|---|---|---|---|
| ||||
/*
* Method Stream.play() is called to start playback of the stream.
*/
playStream.play(); |
4. Receiving from the server an event confirming successful playing of the stream.
StreamStatusEvent, status PLAYING code
Code Block | ||||
---|---|---|---|---|
| ||||
/**
* Callback function for stream status change is added to display the status.
*/
playStream.on(new StreamStatusEvent() {
@Override
public void onStreamStatus(final Stream stream, final StreamStatus streamStatus) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (!StreamStatus.PLAYING.equals(streamStatus)) {
Log.e(TAG, "Can not play stream " + stream.getName() + " " + streamStatus);
mStatusView.setText(streamStatus.toString());
} else if (StreamStatus.NOT_ENOUGH_BANDWIDTH.equals(streamStatus)) {
Log.w(TAG, "Not enough bandwidth stream " + stream.getName() + ", consider using lower video resolution or bitrate. " +
"Bandwidth " + (Math.round(stream.getNetworkBandwidth() / 1000)) + " " +
"bitrate " + (Math.round(stream.getRemoteBitrate() / 1000)));
} else {
mStatusView.setText(streamStatus.toString());
}
}
});
}
}); |
...
6. Stopping the playback of the stream.
session.disconnect(); code
Code Block | ||||
---|---|---|---|---|
| ||||
} else {
mStartButton.setEnabled(false);
/**
* Connection to WCS server is closed with method Session.disconnect().
*/
session.disconnect();
} |
7. Receiving from the server an event confirming the playback of the stream is stopped.
ConnectionStatusEvent DISCONNECTED code
...
language | java |
---|---|
theme | RDark |
...
Include Page | ||||
---|---|---|---|---|
|