Windows Phone 8.1 Toast Notification not playing custom sound

我的未来我决定 提交于 2019-12-25 00:29:57

问题


I am in dire need of your help. I am a Windows app developer and I need my app to play an alarm sound when a toast notification is received. I have tried many different loadouts and everything works fine (Even applying silent='true' in the audio tag), except, ofcourse, for the custom sound.

I have tried my dev server and I have tried with a local toast sent from the app, and nothing seems to work.

My current XML loadout is as follows (I got it from an example in MSDN):

string audio = "ms-winsoundevent:Notification.Mail";
string toastXmlString = "<toast duration='long'>"
                   + "<visual version='1'>"
                   + "<binding template='ToastText02'>"
                   + "<text id='1'>Sound:</text>"
                   + "<text id='2'>" + audio + "</text>"
                   + "</binding>"
                   + "</visual>"
                   + "<audio src='" + audio + "' />"
                   + "</toast>";

The only sound I ever managed to play was the default windows sound. No 'ms-winsoundevent' sounds, no 'ms-appx' or 'ms-appdata' sounds, nothing.

I have checked the headers and XML loadout and compared them to the MSDN documentation. I have tried different formats (mp3 and wav) and different audio clip lengths (18secs, 5secs, 10secs, etc...)

My experience tells me that if there was a problem with the XML loadout or the headers the toast would either not arrive or the text would not show. Other than the sound however, everything works fine.

Thanks in advance for all the help you may offer.


回答1:


I don't know if you have already sorted out your problem, however the issue lies in the duration="long" attribute.

According to MSDN:

Note that neither looping audio nor long-duration toasts are not supported on Windows Phone 8.1. so you have to use duration="short" in order to be able to play the custom sound.

It is a hidden NOTE in the sound tag documentation and is not states clearly and the worst part is the notification will be displayed properly, the silence attribute will be applied but the sound will not be played. Also sound files should be less than 10 seconds but short toast notification is displayed for 5-6 seconds only and the loop will not work as stated.

Hope this helps you :)



来源:https://stackoverflow.com/questions/33365202/windows-phone-8-1-toast-notification-not-playing-custom-sound

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!