Пример плеера для Android
Данный плеер может использоваться для воспроизведения любого типа потока с Web Call Server:
...
На скриншоте ниже представлен пример во время воспроизведения RTSP-потока.
В URL в поле ввода 'WCS URL' 192.168.2.104 - адрес WCS-сервера.
В поле ввода 'Play Stream' - имя потока, в данном случае RTSP URL.
Работа с кодом примера
Для разбора кода возьмем класс PlayerActivity.java примера player, который доступен для скачивания в соответствующей сборке 1.0.1.38.
...
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); /** * 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()); } }); } }); /** * Method Stream.play() is called to start playback of the stream. */ playStream.play(); SharedPreferences sharedPref = PlayerActivity.this.getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putString("play_stream", mPlayStreamView.getText().toString()); editor.apply(); } }); } |
5. Воспроизведение видеопотока.
...