I want to set the video aspect ratio to 1:1 capturing during android media recorder. Im using holder.setFixedSize in onSurfaceChanged method
override fun surfaceChanged(holder: SurfaceHolder, format: Int, w: Int, h: Int) {
// If your preview can change or rotate, take care of those events here.
// Make sure to stop the preview before resizing or reformatting it.
if (mHolder.surface == null) {
// preview surface does not exist
return
}
// stop preview before making changes
try {
mCamera.stopPreview()
} catch (e: Exception) {
// ignore: tried to stop a non-existent preview
}
var parameters: Camera.Parameters = mCamera.getParameters()
holder.setFixedSize(parameters.supportedPreviewSizes[0].width,parameters.supportedPreviewSizes[0].height)
// start preview with new settings
mCamera.apply {
try {
setPreviewDisplay(mHolder)
startPreview()
} catch (e: Exception) {
Log.d(TAG, "Error starting camera preview: ${e.message}")
}
}
}
But it is only resizing the preview size. When I save the video in gallery, it is in full screen size. Also the setFixedSize method stretched the video