Playing in-built webcam feed in a UWP app stopped working after?

Rashika 31 Reputation points
2020-05-28T05:50:41.323+00:00

I'm trying to play the built-in webcam feed in a MediaElement within a UWP app. It works fine for a few users but there is no feed played for most and I'm lost on what could be the issue.

Some observations when the webcam feed doesn't play:

  • The code executes without any exceptions
  • The dialog that requests user permission to access the camera is shown
  • The LED indicating the webcam is in use turns on soon as it is executed, but there is no feed.
  • Skype and Camera apps work fine. The app was working as expected until a week back. A few things that changed in the mean time that could have had an impact are
  • Installed Kaspersky
  • A bunch of windows updates
  • Uninstalled VS2017 professional edition & VS2019 Community edition and installed VS2019 Professional Edition

Some additional information that might be needed to narrow down the reason.

  • Webcam is enabled in the Package manifest of the app
  • App Target version: 18362
  • App Min version: 18362
  • Windows OS Version : 18362

Any help on this would be highly appreciated. Thanks much in advance!

Here is the piece of code used to play the webcam feed where VideoStreamer is a MediaElement.

 private async Task PlayLiveVideo()
        {
            var allGroups = await MediaFrameSourceGroup.FindAllAsync();
            var eligibleGroups = allGroups.Select(g => new
            {
                Group = g,

                // For each source kind, find the source which offers that kind of media frame,
                // or null if there is no such source.
                SourceInfos = new MediaFrameSourceInfo[]
                {
        g.SourceInfos.FirstOrDefault(info => info.DeviceInformation?.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front
            && info.SourceKind == MediaFrameSourceKind.Color),
        g.SourceInfos.FirstOrDefault(info => info.DeviceInformation?.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back
            && info.SourceKind == MediaFrameSourceKind.Color)
                }
            }).Where(g => g.SourceInfos.Any(info => info != null)).ToList();

            if (eligibleGroups.Count == 0)
            {
                System.Diagnostics.Debug.WriteLine("No source group with front and back-facing camera found.");
                return;
            }

            var selectedGroupIndex = 0; // Select the first eligible group
            MediaFrameSourceGroup selectedGroup = eligibleGroups[selectedGroupIndex].Group;
            MediaFrameSourceInfo frontSourceInfo = selectedGroup.SourceInfos[0];

            MediaCapture mediaCapture = new MediaCapture();    
            MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings()
            {
                SourceGroup = selectedGroup,
                SharingMode = MediaCaptureSharingMode.ExclusiveControl,
                MemoryPreference = MediaCaptureMemoryPreference.Cpu,
                StreamingCaptureMode = StreamingCaptureMode.Video, 
            };
            try
            {
                await mediaCapture.InitializeAsync(settings);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("MediaCapture initialization failed: " + ex.Message);
                return;
            } 
            var frameMediaSource1 = MediaSource.CreateFromMediaFrameSource(mediaCapture.FrameSources[frontSourceInfo.Id]);               
            VideoStreamer.SetPlaybackSource(frameMediaSource1);
            VideoStreamer.Play();
        }
Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Fay Wang - MSFT 5,191 Reputation points
    2020-06-01T02:38:35.463+00:00

    Hello,

    Welcome to Microsoft Q&A!

    The problem is that you installed Kaspersky, the setting of Kaspersky Endpoint Security's "advanced Threat Protection/host intrusion prevention" will prevent all apps outside from our dev-harddrive to access the camera. You need to reconfigure that feature in Kaspersky Endpoint Security(e.g. declare necessary locations/clients as a trusted zone).

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful