簡體   English   中英

在wp8.1 rt中播放來自應用的通知音

[英]Play notification tone from app in wp8.1 rt

我們有一個要求,當收到消息時,我們需要在應用程序內播放通知音。

為此,如果一首歌曲正在后台播放並且發出通知,則行為應為:

  1. 背景歌曲/音頻應暫停。
  2. 通知音應播放。
  3. 應該從暫停的位置恢復背景歌曲。

但是我通過以下鏈接通過應用程序播放音頻文件:

1) http://www.jayway.com/2014/04/24/windows-phone-8-1-for-developers-the-background-media-player/這會在后台停止音樂。

2) http://blogs.msdn.com/b/johnkenn/archive/2013/12/31/supporting-background-audio-in-your-windows-8-1-app.aspx

3) https://msdn.microsoft.com/zh-CN/library/windows/apps/xaml/windows.media.systemmediatransportcontrols.aspx

但是這些都不符合我的目的。

在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM