在 Windows 8 Metro App (C#/XAML) 中同时播放两个声音
本文关键字:播放 声音 两个 XAML Windows Metro App | 更新日期: 2023-09-27 18:36:50
I a Windows 8 Metro App (C#/XAML):如何两次触发相同的音效,使其同时播放。
第二部戏应该在第一部戏结束之前开始。
相关问题是:
同时播放两个声音 c#并同时播放两个声音
我找到了这个XNA的类,它可以做我想要的,但在Metro下不可用:http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.audio.soundeffectinstance.aspx
只需为每个音效创建一个单独的媒体元素。
(不确定我每次都需要重新定位文件)
public async void PlayLaserSound()
{
var package = Windows.ApplicationModel.Package.Current;
var installedLocation = package.InstalledLocation;
var storageFile = await installedLocation.GetFileAsync("Assets''Sounds''lazer.mp3");
if (storageFile != null)
{
var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
MediaElement snd = new MediaElement();
snd.SetSource(stream, storageFile.ContentType);
snd.Play();
}
}