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) 中同时播放两种声音
基础教程推荐
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
