libstreaming:在流式传输时更改预览曲面

时间:2017-12-15 19:05:57

标签: android surfaceview libstreaming

我在一个准系统庄园中调用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();

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

0 个答案:

没有答案