Versions Compared

Key

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

Example of player for Android

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.104 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 class PlayerActivity.java of the player example version with hash 4ed4c6d77, which can be downloaded with corresponding build 1.0.1.3.

1. Initialization of the API. line 61

Code Block
languagejs
themeRDark
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 Start button is clicked. line 89

Code Block
languagejs
themeRDark
session = Flashphoner.createSession(sessionOptions);


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

  • URL of WCS server
  • SurfaceViewRenderer, which will be used to play video stream

Callback functions for session events are added (line 94)

  • onConnected() - will be called when connection is successfully established
  • onDisconnection() - will be called when connection is closed
Code Block
languagejs
themeRDark
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 176

Code Block
languagejs
themeRDark
session.connect(new Connection());


3. Playback of video stream.

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

Code Block
languagejs
themeRDark
playStream = session.createStream(streamOptions);


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

Code Block
languagejs
themeRDark
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)) {
                    .....
                }
        }
    }
});


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

Code Block
languagejs
themeRDark
playStream.play();


5. Disconnection. line 188

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

Code Block
languagejs
themeRDark
session.disconnect();