【问题标题】:What is the proper way of using the Windows.Media.Miracast namespace?使用 Windows.Media.Miracast 命名空间的正确方法是什么?
【发布时间】:2019-09-27 07:03:47
【问题描述】:

我正在通过应用程序中的 Miracast 进行屏幕投射,但不确定如何使用 Windows.Media.Miracast 命名空间。由于命名空间是其中一部分的 Windows 10 1903 更新的时间较短,因此 Internet 上存在的信息有限。

目前我发现的唯一东西是this documentation

我的问题是有人知道使用这个命名空间的正确方法是什么吗?在网上找到的任何示例或资源都会有很大帮助。

干杯。

【问题讨论】:

  • API 似乎只适用于构建 Miracast 接收器,而不是 Miracast 源。您要构建什么样的应用程序?
  • 嗯好吧,这是一个可以作为来源的应用程序。我想构建一个应用程序,该应用程序可以从源投射到定义的接收器,而无需通过 Windows 10 Connect 菜单。

标签: c# windows windows-10 miracast


【解决方案1】:

这三个示例项目演示了可在 UWP 应用程序中使用的各种 MiraCast 源 API。不确定 UWP 以外的情况。

我个人在 Windows IoT Core 上使用如下代码来投射我的整个屏幕

扫描设备:

miraDeviceWatcher = DeviceInformation.CreateWatcher(CastingDevice.GetDeviceSelector(CastingPlaybackTypes.Video)); 
miraHandlerAdded = new TypedEventHandler<DeviceWatcher, DeviceInformation>(async (watcher, deviceInfo) =>
{
   await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
   {
      //Add each discovered device to our listbox
      CastingDevice addedDevice = await CastingDevice.FromIdAsync(deviceInfo.Id);
      var disp = new CastingDisplay(addedDevice); //my viewmodel
      MiraDevices.Add(disp); //ObservableCollection
   });
});
miraDeviceWatcher.Added += miraHandlerAdded;

连接到选定的设备:

public async Task StartCasting(CastingDisplay castee)
{
   //When a device is selected, first thing we do is stop the watcher so it's search doesn't conflict with streaming
   if (miraDeviceWatcher.Status != DeviceWatcherStatus.Stopped)
   {
      miraDeviceWatcher.Stop();
   }

   //Create a new casting connection to the device that's been selected
   connection = castee.Device.CreateCastingConnection();
   //Register for events
   connection.ErrorOccurred += Connection_ErrorOccurred;
   connection.StateChanged += Connection_StateChangedAsync;

   var image = new Windows.UI.Xaml.Controls.Image();
   await connection.RequestStartCastingAsync(image.GetAsCastingSource());
}

此图像仅用作投射源。一旦建立连接,我的整个屏幕就会被广播。该行为未记录在案。希望它不会在未来的更新中得到“修复”。

【讨论】:

    猜你喜欢
    • 2012-01-03
    • 1970-01-01
    • 2015-11-29
    • 2017-12-23
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    • 2015-09-01
    相关资源
    最近更新 更多