play two sounds simultaneously in Windows 8 Metro App (C#/XAML)(在 Windows 8 Metro App (C#/XAML) 中同时播放两种声音)
问题描述
我是一个 Windows 8 Metro 应用程序 (C#/XAML):如何触发两次相同的音效,使其同时播放.
I a Windows 8 Metro App (C#/XAML): How can I trigger the same sound effect twice so that it plays simultaneously.
第二场比赛应该在第一场比赛结束之前开始.
The second play should start before the first has finished.
相关问题是:
同时播放两个声音c#和同时播放两个声音
我为 XNA 找到了这个类,它可以满足我的需求,但在 Metro 下不可用:http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.audio.soundeffectinstance.aspx
I found this class for XNA which does what I want, but is not available under Metro: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.audio.soundeffectinstance.aspx
推荐答案
只需为每个音效创建一个单独的媒体元素.
Just create a separate media element for every sound effect.
(不确定我是否每次都需要重新定位文件)
(not sure I need to relocate the file every time)
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();
}
}
这篇关于在 Windows 8 Metro App (C#/XAML) 中同时播放两种声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Windows 8 Metro App (C#/XAML) 中同时播放两种声音


- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01