在 Windows 8 Metro App (C#/XAML) 中同时播放两种声音 [英] play two sounds simultaneously in Windows 8 Metro App (C#/XAML)

查看:21
本文介绍了在 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) 中同时播放两种声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆