本文介绍了在Windows中同时播放两个声音8地铁应用程序(C#/ XAML)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 8地铁应用程序(C#/ XAML):
我怎么能触发两次相同的声音效果,使其同时播放

I a Windows 8 Metro App (C#/XAML):How can I trigger the same sound effect twice so that it plays simultaneously.


和的

Playing two sounds simultaneously c#and Play two sounds simultaneusly

我发现这个类XNA这不会是我想要的,但不可用地铁在:

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地铁应用程序(C#/ XAML)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 19:00
查看更多