在 UWP 应用程序中播放内置网络摄像头后停止工作?

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

我正在尝试在 UWP 应用中的 MediaElement 中播放内置网络摄像头。它对一些用户来说工作正常,但对大多数用户来说没有播放提要,我不知道可能是什么问题。

网络摄像头不播放时的一些观察:

可能需要一些额外的信息来缩小原因范围。

如有任何帮助,我们将不胜感激。提前致谢!

这是一段用于播放网络摄像头源的代码,其中 VideoStreamer 是 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();
    }

正如 Faywang-MSFT here 所提到的,它在卡巴斯基将应用程序标记为受信任后起作用。