我已经在没有任何自定义声音的情况下测试了我的应用程序,默认声音播放完美
var prayerName = App_Code.helperMethods.getPrayerNameforNotification(i);
ToastAudio tA = new ToastAudio();
tA.Src = new Uri("ms-appx:///Sounds/AnyDay.mp3");
ToastContent con = new ToastContent()
{
Visual = new ToastVisual()
{
TitleText = new ToastText() { Text = "Namaz Pro" },
BodyTextLine1 = new ToastText() { Text = prayerName + " in " + App_Code.StoreRetrieveSettingsAssist.getLocation() },
BodyTextLine2 = new ToastText() { Text = App_Code.helperMethods.userSpecifiedTimeFormat(myPT, DateTime.Today) },
},
Launch = DateTime.Today.ToString("ddMMyyyy") + i.ToString(),
Scenario = ToastScenario.Alarm,
Duration = ToastDuration.Short,
Audio = tA,
};
return con;
我的解决方案中有三个项目:
应用代码
BackgroundTasks(引用 App_Code)
Namaz Pro(引用 App_Code){MAIN APP}
我的自定义声音是“AnyDay.mp3”(Elvis 的好奇声音)放置在 App_Code 项目中,如下所示:App_Code/Sounds/AnyDay.mp3
我上面提到的 block 所在的代码也在 App_Code 中。
但是声音根本不播放,Notification 就像是静音一样。 我什至尝试了 .wav 文件,但结果仍然相同。
最佳答案
由于您的自定义声音在 App_Code 项目中为:App_Code/Sounds/AnyDay.mp3,因此您需要使用此 URI:
ms-appx:///App_Code/Sounds/AnyDay.mp3
而不是 ms-appx:///Sounds/AnyDay.mp3
。
While using the
ms-appx:
scheme, Windows Runtime APIs do not support URIs of typeUriKind.Relative
, so you typically use the signature that infers the UriKind and make sure you've specified a valid absolute URI including the scheme and authority.
要访问存储在应用程序附带的框架或库包中的文件,我们可以使用绝对 URI,例如:
ms-appx:///App_Code/Sounds/AnyDay.mp3
如果我们使用 ms-appx:///Sounds/AnyDay.mp3
,则 Toast 通知将使用“Namaz”下的“AnyDay.mp3” Pro/Sounds”,但由于没有这样的资源,toast 通知将作为静音。
关于c# - 通知自定义声音不播放 UWP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35297685/