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) 中同时播放两种声音
基础教程推荐
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
