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) 中同时播放两种声音
基础教程推荐
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 如果条件可以为空 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 将数据集转换为列表 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
