Set FFmpegRecorder in half screen layout
santoshshikare opened this issue · comments
i want to implement FFmpegRecorder in this custom layout, means first half is image and second half is FFmpegREcorder. I have tried to implement from sample project but i am getting following error
java.lang.ArithmeticException: / by zero
at customecamera.com.ffmpegcamera.FixedRatioCroppedTextureView.onMeasure_Original(FixedRatioCroppedTextureView.java:40)
at customecamera.com.ffmpegcamera.FixedRatioCroppedTextureView.onMeasure(FixedRatioCroppedTextureView.java)
at android.view.View.measure(View.java:22035)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6622)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at customecamera.com.ffmpegcamera.FixedAspectRatioFrameLayout.onMeasure_Original(FixedAspectRatioFrameLayout.java:68)
at customecamera.com.ffmpegcamera.FixedAspectRatioFrameLayout.onMeasure(FixedAspectRatioFrameLayout.java)
at android.view.View.measure(View.java:22035)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:22035)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6622)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22035)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6622)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22035)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:22035)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6622)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure_Original(ContentFrameLayout.java:139)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java)
at android.view.View.measure(View.java:22035)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6622)
at android.support.v7.widget.ActionBarOverlayLayout.onMeasure_Original(ActionBarOverlayLayout.java:400)
at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java)
at android.view.View.measure(View.java:22035)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:22035)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:590)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:343)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:547)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:681)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
waiting for reply..
It clearly shows "java.lang.ArithmeticException: / by zero", maybe you didn't set mCroppedWidthWeight
.
I think you should debug FixedRatioCroppedTextureView.onMeasure()
method to have a look yourself.
Following class is to create custome square view framelayout
public class FixedAspectRatioFrameLayout extends FrameLayout
{
private int mAspectRatioWidth;
private int mAspectRatioHeight;
public FixedAspectRatioFrameLayout(Context context)
{
super(context);
}
public FixedAspectRatioFrameLayout(Context context, AttributeSet attrs)
{
super(context, attrs);
init(context, attrs);
}
public FixedAspectRatioFrameLayout(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs)
{
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FixedAspectRatioFrameLayout);
mAspectRatioWidth = a.getInt(R.styleable.FixedAspectRatioFrameLayout_aspect_ratio_width, 1);
mAspectRatioHeight = a.getInt(R.styleable.FixedAspectRatioFrameLayout_aspect_ratio_height, 1);
a.recycle();
}
// **overrides**
@Override protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
{
int originalWidth = MeasureSpec.getSize(widthMeasureSpec);
int originalHeight = MeasureSpec.getSize(heightMeasureSpec);
int calculatedHeight = originalWidth * mAspectRatioHeight / mAspectRatioWidth;
int finalWidth, finalHeight;
if (calculatedHeight > originalHeight)
{
finalWidth = originalHeight * mAspectRatioWidth / mAspectRatioHeight;
finalHeight = originalHeight;
}
else
{
finalWidth = originalWidth;
finalHeight = calculatedHeight;
}
super.onMeasure(
MeasureSpec.makeMeasureSpec(finalWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(finalHeight, MeasureSpec.EXACTLY));
}
}
Desing test layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/topContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/colorPrimary"
android:orientation="vertical">
<customecamera.com.ffmpegcamera.FixedAspectRatioFrameLayout
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/pick_imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:src="@mipmap/ic_launcher" />
</customecamera.com.ffmpegcamera.FixedAspectRatioFrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/MainContainer"
android:background="@color/yello"
android:layout_width="match_parent"
android:layout_height="match_parent">
</View>
<View
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/MainContainer"
android:background="@color/yello"
android:layout_width="match_parent"
android:layout_height="match_parent">
</View>
<customecamera.com.ffmpegcamera.FixedAspectRatioFrameLayout
android:id="@+id/MainContainer"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<customecamera.com.ffmpegcamera.FixedRatioCroppedTextureView
android:id="@+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</customecamera.com.ffmpegcamera.FixedAspectRatioFrameLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
and else part i have added from your sample project
i have set width to match parent and on measure i am getting device width
i have given 1:1 for mAspectRatioWidth and mAspectRatioHeight
but still it show error
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FixedAspectRatioFrameLayout);
mAspectRatioWidth = a.getInt(R.styleable.FixedAspectRatioFrameLayout_aspect_ratio_width, 1);
mAspectRatioHeight = a.getInt(R.styleable.FixedAspectRatioFrameLayout_aspect_ratio_height, 1);
a.recycle();
Check the value of FixedRatioCroppedTextureView.mCroppedWidthWeight
when onMeasure
is called.
its getting zero
got solved now not crashing
thank you for help..