java.lang.RuntimeException: Fail to connect to camera service
Hi
Sometimes i got a crash (Motorola Moto E Android 4.4.4, or other device from Fabric
)
FATAL EXCEPTION: cameraThread
Process: pl.xxx.app, PID: 1321
java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.native_setup(Native Method)
at android.hardware.Camera.<init>(Camera.java:364)
at android.hardware.Camera.open(Camera.java:319)
at com.pedro.encoder.input.video.Camera1ApiManager$1.run(Camera1ApiManager.java:132)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)
It happens when I start streaming, then I close the activity, and I immediately go back to activity and start again. It looks like the camera resource did not release.
I can not replicate this in your example app on the same device. I don't know why. Maybe because in my app everything happens automatically.
What can be a problem? How to always release Camera?
Are you doing stop stream in onPause? https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/app/src/main/java/com/pedro/rtmpstreamer/customexample/RtmpActivity.java#L301
Yes
Full log: https://pastebin.com/dzrCMvz5
Ok my bad, example had a error. Now this is fixed. The problem was that when you call stopStream you are not closing preview, you need call stopPreview before stopStream to release camera properly. Example: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/app/src/main/java/com/pedro/rtmpstreamer/defaultexample/ExampleRtmpActivity.java#L107
My custom activity work for this XD: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/app/src/main/java/com/pedro/rtmpstreamer/customexample/RtmpActivity.java#L403
It looks like it works now. thx @pedroSG94