1

我在准系统中调用 libstreaming ...我希望能够在不中断流式传输的情况下更改预览 surfaceView。

@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));
}

我在尝试切换预览表面时遇到问题。当我尝试以下操作时,我没有得到任何改变:

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

还尝试了一些简单但不起作用的方法:

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

欢迎任何关于如何做到这一点的见解。

4

0 回答 0