0

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

到目前为止,我发现的唯一东西就是这个文档

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

干杯。

4

1 回答 1

3

这三个示例项目演示了可从 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());
}

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

于 2019-06-18T16:27:46.673 回答