目前,我开发了Windows 10移动应用程序,可以播放声音/音频功能。
当我编写此语句来播放音频/声音时,当点击图像点击事件时,它将显示错误。
源代码如下:
MediaElement mysong = new MediaElement();
try
{
var folder = await StorageFolder.GetFolderFromPathAsync(@"ms-appx://Assets/Media/");
if (folder != null)
{
var file = await folder.GetFileAsync("police_alarm.mp3");
if (file != null)
{
var stream = await file.OpenReadAsync();
mysong.SetSource(stream, file.ContentType);
mysong.Volume = 100;
mysong.Play();
}
}
else
{
MessageDialog dialog = new MessageDialog("Siren can't play !!! Please keep yourself safe !!!", "Error");
await dialog.ShowAsync();
}
}
catch(Exception ex)
{
MessageDialog dialog = new MessageDialog(ex.ToString(), "Error");
await dialog.ShowAsync();
}
非常感谢。