Using one MediaCapture in multiple CaptureElement.Source

78 Views Asked by At

I'm trying to preview one MediaCapture to multiple(2) CaptureElement's. For example I have one big CaptureElement and one mini - map of it in the screen corner. Is it possible?

When I'm trying to set initialized Capture to one CaptureElement, everything works fine, but when I share it in 2 places, I'm getting error like "unsupported operation for current state".

Here's the code example, I'm trying to use:

await video.TryStopPreviewingAsync();
minimap.Source = null;
await minimap.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
    minimap.Source = video.Stream.Capture;
});
await video.TryStartPreviewingAsync();

minimap is second CaptureElement,video.Resources.First.Stream.Capture is currently previewing capture.

TryStop/StartPreviewingAsynccalls Capture.Stop/StartPreviewingAsync()

I tried to stop previewing first capture, set it like a source in 2 places and then starts previewing on both captureelements, but I got error.

1

There are 1 best solutions below

2
Nico Zhu On BEST ANSWER

I'm getting error like "unsupported operation for current state".

It's by design, and it will throw exception when pass the Capture to multiple CaptureElement.

For your scenario, the better way is use image control replace CaptureElement, and process frame with MediaFrameReader, and then generate bitmap for each frame within FrameArrived.

And here is official code sample that you could refer to.