Open Lonnaty opened 1 year ago
And this line while (textureView.SurfaceTexture == null) Thread.Sleep(100);
located in the StartPreview method
causes the application to freeze if the SurfaceTexture has not been loaded beforehand because you then block via Thread.Sleep, it will continue indefinitely.
You need to use SurfaceTextureAvailable Event:
https://learn.microsoft.com/en-us/dotnet/api/android.views.textureview.surfacetextureavailable?view=xamarin-android-sdk-13&viewFallbackFrom=xamarin-android-sdk-12
But it seems the author forgot about his plugin and I’m writing these comments just like that
Because the code uses the OutputConfiguration class available only from API 24
surfaces.Add(new OutputConfiguration(previewSurface));
surfaces26.Add(previewSurface);
previewBuilder.AddTarget(previewSurface);
if (imgReader != null)
{
surfaces.Add(new OutputConfiguration(imgReader.Surface));
surfaces26.Add(imgReader.Surface);
}
if (mediaRecorder != null)
{
surfaces.Add(new OutputConfiguration(mediaRecorder.Surface));
surfaces26.Add(mediaRecorder.Surface);
previewBuilder.AddTarget(mediaRecorder.Surface);
}
Need to add something like this
if (OperatingSystem.IsAndroidVersionAtLeast(24))
{
surfaces.Add(new OutputConfiguration(previewSurface));
}
I also had a situation that map.GetOutputSizes returns an empty array and the connection to the camera was not completed.
StreamConfigurationMap map = (StreamConfigurationMap)camChars.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
videoSize = ChooseVideoSize(map.GetOutputSizes(Class.FromType(typeof(ImageReader))));
var maxVideoSize = ChooseMaxVideoSize(map.GetOutputSizes(Class.FromType(typeof(ImageReader))));
I used the standard resolution of 1280x720 for this situation.
try
{
videoSize = ChooseVideoSize(map.GetOutputSizes(Class.FromType(typeof(ImageReader))));
maxVideoSize = ChooseMaxVideoSize(map.GetOutputSizes(Class.FromType(typeof(ImageReader))));
}
catch
{
videoSize = new Size(1280, 720);
maxVideoSize = new Size(1280, 720);
}