[英]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.