Versions Compared

Key

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

...

При инициализации методу init() передается объект Сontext.

Code Block
languagejsjava
themeRDark
Flashphoner.init(this);

...

  • URL WCS-сервера
  • SurfaceViewRenderer remoteRenderer, который будет использоваться для воспроизведения видеопотока
Code Block
languagejsjava
themeRDark
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);

...

Session.connect(). код

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

...

session.onConnected() код

Code Block
languagejsjava
themeRDark
@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());
            ...
        }
    });
}

...

При создании потока методу Session.createStream() передается объект StreamOptions с именем видеопотока для воспроизведения

Code Block
languagejsjava
themeRDark
StreamOptions streamOptions = new StreamOptions(mPlayStreamView.getText().toString());
            
/**
  * Stream is created with method Session.createStream().
  */
playStream = session.createStream(streamOptions);
            
/**
  * 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);
                } 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());
                }
            }
        });
    }
});
            
/**
  * Method Stream.play() is called to start playback of the stream.
  */
playStream.play();

...

Session.disconnect() код

Code Block
languagejsjava
themeRDark
session.disconnect();

...

session.onDisconnection() код

Code Block
languagejsjava
themeRDark
@Override
public void onDisconnection(final Connection connection) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mStartButton.setText(R.string.action_start);
            mStartButton.setTag(R.string.action_start);
            mStartButton.setEnabled(true);
            mStatusView.setText(connection.getStatus());
        }
    });
}