Reputation: 48262
I'm currently using onPreviewCallback so I can capture frames from camera when in preview and stream them via http.
That works but then I issue a command to start recording and, it seems, I do not have a preview callback anymore.
So, how do I keep the preview callback so I can both send the frames from the surface to my server AND record the video on the device?
Upvotes: 6
Views: 4272
Reputation: 19
You can call these methods after your media recorder.start() being called as following :
camera.reconnect();
camera.setPreviewCallback();
surfaceview.getHolder().addCallback();
The reasons:
I have ever been the same issue as yours in my application, and i fixed it by this. Hope it can resolve your problems!
Upvotes: 1
Reputation: 582
Once I got the camera and MediaRecorder to start and stop recording without crashing (was not easy) I still had a problem like you described, where the preview callback would stop getting called.
The fix I finally found was adding a call to setPreviewCallback after mediaRecorder.start(), and another after mediaRecorder.stop(). Not sure if this is correct, but it worked on the Razr M I am testing on.
Upvotes: 0
Reputation: 23268
I didn't work for quite long time with Android Camera. However, as I remember
1) onPreviewCallback isn't called while you are recording
It's mentioned in couple of questions:
Camera onPreviewFrame not called How to show real time filtered camera preview while recording videos?
2) I saw that it was handled in SipDroid and couple of other Android SIP clients following way (this was a 1-2 years ago, so this method could be outdates):
3) You can use onPreviewFrame + start AudioRecorder and encode it yourself (using ffmpeg or something like that) to mp4 file. This way you don't need to start MediaRecorder recording.
Upvotes: 5