声音来自&ms; winsoundedevent'方案没有在Windows 10 Mobile上播放

时间:2016-10-01 07:29:27

标签: uwp windows-10-mobile

我使用通知开发UWP应用程序。我想为他们设置来自 winsoundevent 计划的自定义声音。在桌面版本上它工作正常,但在移动声音没有播放。如何在移动版上播放此声音?调查代码:

 RingtoneMediaElement.Source = new Uri("ms-winsoundevent:Notification.Looping.Alarm7", UriKind.RelativeOrAbsolute);
 RingtoneMediaElement.AutoPlay = true;
 RingtoneMediaElement.Play();

1 个答案:

答案 0 :(得分:0)

ms-winsoundeventToast schema之一。因此,此方案用于带有<audio src="ms-winsoundevent:Notification.Mail" loop="false"/>标记的Toast内容,如private void btnpushnotification_Click(object sender, RoutedEventArgs e) { XmlDocument doc = new XmlDocument(); string xml= $@" <toast scenario='incomingCall'> <visual> <binding template='ToastGeneric'> <text>Looping Audio Toast</text> <text>This toast uses looping audio, useful for scenarios like phone calls.</text> </binding> </visual> <actions> <action arguments = 'answer' content = 'answer' /> <action arguments = 'ignore' content = 'ignore' /> </actions> <audio src='ms-winsoundevent:Notification.Looping.Alarm7' loop='true'/> </toast>"; doc.LoadXml(xml); var toast = new ToastNotification(doc); ToastNotificationManager.CreateToastNotifier().Show(toast); }

我没有找到任何关于此方案的官方文件可以作为媒体元素的媒体来源得到支持。在我看来,我们不应该将它用作媒体源,尽管它可以在本地机器上播放。

为了满足您为通知设置自定义声音的要求,此方案可以正常工作,示例代码如下:

<img style = "width:300px;height 300px;">

我在移动模拟器和Lumia 640上测试了这个示例,windows 10 build 14393.它们都运行良好。此外,对于自定义声音,audio中提到的以前的Windows Phone操作系统存在一个已知问题:

  

...自定义音频不起作用。我们正在调查此问题。截至目前,ms-appx和ms-appdata都不能在桌面上工作,只有ms-appdata可以在Mobile上运行。

有关此已知问题的详细信息以及如何解决,请参阅this article

有关示例代码的更多详细信息,请参阅this threadAudio scenario