FFmpegRecorder
FFmpegRecorder copied to clipboard
Fullscreen camera preview
I want make preview based on device width and height.look like its not working can anyone help me to do that
You can make the preview TextureView fullscreen as long as you can find a supported preview size of the camera which has matching width-height ratio, otherwise the preview will be distorted.
can u provide sample code for that?
You don't need PREFERRED_PREVIEW_WIDTH and PREFERRED_PREVIEW_HEIGHT variables
add below code in onCreate() and use mPreviewWidth and mPreviewHeight where above variables needed.
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
//assigning reverse values, because preview sizes are landscape by default
//noinspection SuspiciousNameCombination
mPreviewWidth = displayMetrics.heightPixels;
//noinspection SuspiciousNameCombination
mPreviewHeight = displayMetrics.widthPixels;
And also chnage TextureView
public class FullScreenTextureView extends TextureView {
public FullScreenTextureView(Context context) {
super(context);
}
public FullScreenTextureView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FullScreenTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int measuredWidth = getMeasuredWidth();
int measuredHeight = getMeasuredHeight();
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
if (0 == measuredWidth || 0 == measuredHeight) {
setMeasuredDimension(width, height);
} else {
if (width < height * measuredWidth / measuredHeight) {
setMeasuredDimension(height * measuredWidth / measuredHeight, height);
} else {
setMeasuredDimension(width, width * measuredHeight / measuredWidth);
}
}
}
}