pedroSG94 / RTSP-Server

Plugin of rtmp-rtsp-stream-client-java to stream directly to RTSP player.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to start video streaming automatically when CameraDemoActivit is ready?

gushangzao007 opened this issue · comments

My Target: start video streaming automatically when CameraDemoActivit is ready.

What I have done: move following code to the onCreate function of CameraDemoActivit.

https://github.com/pedroSG94/RTSP-Server/blob/c72bf5a3563c220d9b14dba4b28d83fbe81d0fb5/app/src/main/java/com/pedro/sample/CameraDemoActivity.kt#L99C21-L99C21

What is the test result?

  1. video surface is always black in screen
  2. got Error from Toast: connection faild , sps....is nulll..bla bla

could you help to advise a correct method to start streaming automatically?
Thank you very much。

there are detail error information
Screenshot_20231129_113613_com maygarden ffmpeg5
errorLog.txt

by the way, I'm using Timer class in onCreate function as a work around method to temporally solve it. however personally I think this is not an elegant way.

Hello,

You have that error because you need wait until the view is totally created.
The view is created when this callback is called:

override fun surfaceChanged(surfaceHolder: SurfaceHolder, i: Int, i1: Int, i2: Int) {

That is the reason because I call start preview here and not in onCreate.
And destroyed in this one:

override fun surfaceDestroyed(surfaceHolder: SurfaceHolder) {

Thanks a lot buddy! let me try

cool! work perfect! Thanks again!