This streamer can be used to publish and record WebRTC video stream on Web Call Server.
On the screenshot below the example is displayed when connection to server is closed and stream publication is stopped.
In the URL specified in the input field
Above the input field video from the camera is displayed.
Under the input field are located
To analyze the code, let's take class StreamRecordingActivity.java of the stream-recording example version with hash 4ed4c6d77, which can be downloaded with corresponding build 1.0.1.3.
1. Initialization of the API. line 72
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 Record button is clicked. line 109
session = Flashphoner.createSession(sessionOptions); |
Session is created with method createSession(), to which object SessionOptions (line 103) with the following parameters is passed
Callback functions for session events are added (line 114)
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 224
session.connect(new Connection()); |
3. Video streaming.
After establishing connection to the server, new video stream is created with method Session.createStream(). line 141
Object StreamOptions (line 135) with is passed to the method
publishStream = session.createStream(streamOptions); |
Callback function for processing stream statuses is added. (line 146)
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 173
publishStream.publish(); |
4. Filename of the recording. line 158
When the stream is published, method Stream.getRecordName() is used to get the filename of the stream recording.
recordFilename = stream.getRecordName(); |
5. Download link. line 201
Stream recordings are saved to directory WCS_HOME/client/records.
When the session is closed, download link for the recording is formed.
String url = "http://" + uri.getHost() +":9091/client/records/" + recordFilename; |
Here
URL of the file is used to play the recording in the media player of the example.
6. Disconnection. line 236
Method Session.disconnect() is called to close connection to the server.
session.disconnect(); |