MediaCapture stops recording footage without triggering the Failed event or any other notification

Alfonso Crawford 136 Reputation points
2021-02-05T00:22:10.017+00:00

In my UWP app, MediaCapture is repeatedly failing to record, and I can't even get information as to what is failing. I've hooked into the Failed even and induced the failure I'm looking for, and I still end up with nothing.

The problem that occurs is that everything will run normally, but the resulting video file is only a second long. No warnings or exceptions come up during runtime. Below is what I'm using to display the event information:

void MediaCapture_Failed(MediaCapture sender, MediaCaptureFailedEventArgs errorEventArgs)
{
 Debug.WriteLine("THE MEDIA CAPTURE HAS FAILED");
 EndRecording(null, null); // This method calls StopAsync() and other general app logistics.

 ContentDialog failure_dialog = new ContentDialog
 {
 Title = "Recording Failure — " + errorEventArgs.Code.ToString(),
 Content = errorEventArgs.Message,
 CloseButtonText = "Acknowledge"
 };

 _ = failure_dialog.ShowAsync();
}

When is the Failed event meant to occur? It's not happening when MediaCapture stops saving data to a file, so I don't know when I need to rely on it. What event/exception is in place for when MediaCapture stops recording/receiving footage?

What could be going wrong within MediaCapture? I've accessed the same device from software like OBS Studio and not had this problem, so I presume something within my code is to blame. The problem I'm facing only happens when I try to pull video and audio from the same device. The project could abide by simply using a looping music file instead of the capture device's audio, but that too is something I haven't been able to figure out yet.

Everything else with UWP has been flowing beautifully. A/V has been the only hitch so far. I'd love to keep working with the platform, if possible. I thank you in advance for any insight you can provide into what's going wrong with my implementation of MediaCapture.

Universal Windows Platform (UWP)
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.