libstreaming: Changing Preview Surface while streaming

161 views Asked by At

I am invoking libstreaming in a barebones manor... I would like to be able to change the preview surfaceView without interrupting the streaming.

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.activity_main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    mSurfaceView1 = (SurfaceView) findViewById(R.id.surface1);
    mSurfaceView2 = (SurfaceView) findViewById(R.id.surface2);

    // Sets the port of the RTSP server to 1234
    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
    editor.putString(RtspServer.KEY_PORT, String.valueOf(1234));
    editor.commit();

    mSurfaceView1.getHolder().addCallback(this);

    // Configures the SessionBuilder
    mSession = SessionBuilder.getInstance()
            .setSurfaceView(mSurfaceView1)
            .setPreviewOrientation(90)
            .setContext(getApplicationContext())
            .setAudioEncoder(SessionBuilder.AUDIO_NONE)
            .setVideoEncoder(SessionBuilder.VIDEO_H264)
            .setCallback(this)
            .build();


    // Starts the RTSP server
    this.startService(new Intent(this,RtspServer.class));
}

I am running into problems trying to switch the preview surfaces. When I try the following I get no change:

   private void changePreviewSurface(SurfaceView surfaceView)
{
    mSession.stopPreview();
    surfaceView.getHolder().addCallback(this);
    mSession.setSurfaceView(surfaceView);
    mSession.startPreview();
}

Also tried something simple which did not work:

SessionBuilder.getInstance()
  .setSurfaceView(mSurfaceView2)
  .build();

Would welcome any insight into how this should be done.

0

There are 0 answers