[英]Play notification tone from app in wp8.1 rt
我们有一个要求,当收到消息时,我们需要在应用程序内播放通知音。
为此,如果一首歌曲正在后台播放并且发出通知,则行为应为:
但是我通过以下链接通过应用程序播放音频文件:
1) http://www.jayway.com/2014/04/24/windows-phone-8-1-for-developers-the-background-media-player/这会在后台停止音乐。
但是这些都不符合我的目的。
在wp8中,我们可以用这种方式做到这一点。
任何实现所需功能的方向?
如果您是在用户收到消息时向他们发送烤面包通知,请通过添加audio
标签在通知有效负载中包含自定义声音:
<toast launch=\"$param\">
<audio src=\"ms-appx:///Assets/Sounds/$sound.wav\"/>
<visual>
<binding template=\"ToastText02\">
<text id=\"1\">$title</text>
<text id=\"2\">$msg</text>
</binding>
</visual>
</toast>
为了使自定义声音起作用,您需要在项目中包含sound.wav
并可以指定路径。 我将其放在我的Assets/Sounds/
文件夹中,您可以指定其他内容。
当您收到消息时,也可以尝试在应用内发送带有声音的祝酒词:
var notificationContent = "...xml...";
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(notificationContent);
var toastNotification = new ToastNotification(xmlDocument);
toastNotification.SuppressPopup = true;
ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
其中notificationContent
与上述XML的格式相同,只是转义了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.