cameraview
cameraview copied to clipboard
camera view lag showing when call mCamera.stop()
The cameraview object is causing lag when used in a view pager. When scrolling back from cameraview to anothertab, the transition isnt smooth. Can you please suggest if there is a way to handle it smoothly.
@ashish0121 Any update on this?
- In view pager when ViewPager.SimpleOnPageChangeListener() function onPageSelected is called, then you can call in your mCamera.stop() if it doesnt match with camera preview page.
- The view pager was still causing jerk but to a lesser extent. So it was kind of a partial fix.
- You can try combination of coordinator layout with view pager though i haven't tried it myself.
Yes that is what I'm doing, except I'm starting up another camera in another fragment when I swipe to switch fragments, i.e. I call mCamera1.stop()
for Fragment1, and mCamera2.start()
for Fragment2.
I was able to resolve this using an async task:
private static class StopStartCameraAsyncTask extends AsyncTask<Void, Void, Void>
{
private final CameraView cameraToStop;
private final CameraView cameraToStart;
StopStartCameraAsyncTask(@NonNull CameraViewListener cameraToStop, @NonNull CameraViewListener cameraToStart)
{
this.cameraToStart = cameraToStart;
this.cameraToStop = cameraToStop;
}
@Override
protected Void doInBackground(Void... voids)
{
cameraToStop.stopCamera();
return null;
}
@Override
protected void onPostExecute(Void aVoid)
{
super.onPostExecute(aVoid);
cameraToStart.startCamera();
}
}