private void startStream() {

    // grab the main view where our video object resides
    View v = this.findViewById(android.R.id.content);

    v.setKeepScreenOn(true);

    // setup the stream with the user config settings
    stream =
        new R5Stream(
            new R5Connection(
                new R5Configuration(
                    R5StreamProtocol.RTSP,
                    streamParams.host,
                    streamParams.port,
                    streamParams.app,
                    2.0f)));

    // set log level to be informative
    stream.setLogLevel(R5Stream.LOG_LEVEL_INFO);

    // set up our listener
    stream.setListener(
        new R5ConnectionListener() {
          @Override
          public void onConnectionEvent(R5ConnectionEvent r5event) {
            // this is getting called from the network thread, so handle appropriately
            final R5ConnectionEvent event = r5event;

            runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    Context context = getApplicationContext();
                    CharSequence text = event.message;
                    int duration = Toast.LENGTH_SHORT;

                    Toast toast = Toast.makeText(context, text, duration);
                    toast.show();
                  }
                });
          }
        });

    // associate the video object with the red5 SDK video view
    R5VideoView videoView = (R5VideoView) v.findViewById(R.id.video);
    // attach the stream
    videoView.attachStream(stream);
    // start the stream
    stream.play(streamParams.name);
    // update the state for the toggle button
    setStreaming(true);
  }
  private void stopStream() {

    if (stream != null) {
      View v = this.findViewById(android.R.id.content);
      R5VideoView videoView = (R5VideoView) v.findViewById(R.id.video);
      videoView.attachStream(null);
      stream.stop();

      stream = null;
    }
    setStreaming(false);
  }