Skip to content

[BUG] Problems with Some CameraView StopVideoRecording on IOS #3152

@neji94

Description

@neji94

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

HI i have an Problem what appears in some apps and only after recordiong more the around 6 secounds. Whenn it happens the StopVideoRecording function not ends ant it seams so that the TaskCompletionSource used in cambination with AVCaptureMovieFileOutputRecordingDelegate not been set to compleat. But Why and why i cannot recreate it in every app? hasy anywone an idear?

my Used call to start and stop the recording is the following:
` ToogleRecord = new AsyncRelayCommand(async () => {
try
{
if (TakeVideo)
{
Console.WriteLine($"Recording Is video: IsRunning: {VideoIsRunning}");
if (!VideoIsRunning)
{

              if (movieStream != null)
              {
                  try
                  {
                      await movieStream.DisposeAsync();
                  }
                  catch { }
                  movieStream = null;
              }

              if (File.Exists(Path.Combine(FileSystem.Current.AppDataDirectory, "tem_recording.mp4")))
                  File.Delete(Path.Combine(FileSystem.Current.AppDataDirectory, "tem_recording.mp4"));

              movieStream = new FileStream(Path.Combine(FileSystem.Current.AppDataDirectory, "tem_recording.mp4"), FileMode.Create, FileAccess.ReadWrite, FileShare.Read, 4096, true);
              movieStream.Position = 0;
     

              await cameraView.StartVideoRecording(movieStream, CancellationToken.None);
              VideoIsRunning = true;
              Console.WriteLine("Recording Stared");
          }
          else
          {
              Console.WriteLine("Recording stopeding");
              //cameraView.StopCameraPreview();
              await cameraView.StopVideoRecording(CancellationToken.None);
          
              Console.WriteLine("Recording stoped 1");
              await movieStream.DisposeAsync();
              Console.WriteLine("Recording stoped 2");
              movieStream = null;
              VideoIsRunning = false;
              Console.WriteLine("Recording stoped 3");
              returnFunc.Invoke(new List<MediaFile>() { new TakenMediaFile(TakeVideo, new FileStream(Path.Combine(FileSystem.Current.AppDataDirectory, "tem_recording.mp4"), FileMode.Open, FileAccess.Read, FileShare.Read)) });
              Console.WriteLine("Recording stoped");

          }
      }
      else
      {

          Console.WriteLine($"Error: Files Selected count {SelectedFiles?.Count()}");

          var captureImageCTS = new CancellationTokenSource(TimeSpan.FromSeconds(3));
          var photo = await cameraView.CaptureImage(captureImageCTS.Token);
          returnFunc.Invoke(new List<MediaFile>() { new TakenMediaFile(TakeVideo, photo) });
      }
      await OnPropertyChangedAsync(null);
  }
  catch (Exception ex) {
      Console.WriteLine($"Recording Error: {ex}");
  
  }

});`

The CameraView is opend in an Popup.

Expected Behavior

Exiting the function and an filled video stream/file

Steps To Reproduce

Not known. It seams to happen after at least 6 sec. of recording

Link to public reproduction project repository

Could not Create one

Environment

- .NET MAUI CommunityToolkit: 13.0.0
- .NET MAUI CommunityToolkit Camera: 6.0.0
- OS: Ios > 16.0
- .NET MAUI: 10.0.50

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions