If you are looking to know, How to get camera rotation while capturing video with custom camera in android, follow below steps
Step 1:-Declare OrientationEventListener and the variable that hold the orientation value.
OrientationEventListener orientationEventListener;
int orientationValue;
Step 2:-Initialize OrientationEventListener.
if (orientationEventListener == null)
{
orientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL)
{
@Override
public void onOrientationChanged(int orientation)
{
if (orientation >= 315 || orientation < 45) //for portrait upside
{
orientationValue = 1;
}
else if (orientation < 315 && orientation >= 225) //for rightside landscape
{
orientationValue = 3;
}
else if (orientation < 225 && orientation >= 135) //for portrait downside
{
orientationValue = 2;
}
else
{ // orientation <135 && orientation > 45 for leftside landscape
orientationValue = 4;
}
}
};
}
Step 3:-Enable OrientationEventListener when you prepare MediaRecorder
if(orientationEventListener.canDetectOrientation())
{
orientationEventListener.enable();
}
0 Comment(s)