【问题标题】:Playing in-built webcam feed in a UWP app stopped working after?在 UWP 应用中播放内置网络摄像头后停止工作?
【发布时间】:2020-05-27 12:31:34
【问题描述】:

我正在尝试在 UWP 应用内的 MediaElement 中播放内置网络摄像头源。它适用于少数用户,但大多数用户没有播放提要,我不知道可能是什么问题。

网络摄像头无法播放时的一些观察结果:

  • 代码执行没有任何异常
  • 显示请求用户访问相机权限的对话框
  • 指示网络摄像头正在使用的 LED 指示灯会在执行后立即亮起,但没有馈送。
  • Skype 和相机应用运行良好。
  • 该应用程序在一周前按预期运行。同时发生的一些可能产生影响的事情是
    • 已安装卡巴斯基
    • 一堆windows更新
    • 卸载VS2017专业版和VS2019社区版,安装VS2019专业版

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

  • 在应用程序包清单中启用了网络摄像头
  • 应用目标版本:18362
  • 应用最低版本:18362
  • Windows 操作系统版本:18362

对此的任何帮助将不胜感激。非常感谢!

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

【问题讨论】:

  • 我已经在Q&A回复你了,你可以查一下。

标签: c# uwp mediacapture


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 2016-11-20
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 2023-01-17
    相关资源
    最近更新 更多