【问题标题】:play two sounds simultaneously in Windows 8 Metro App (C#/XAML)在 Windows 8 Metro App (C#/XAML) 中同时播放两种声音
【发布时间】:2012-06-09 12:21:41
【问题描述】:

我是一个 Windows 8 Metro 应用程序 (C#/XAML): 如何触发两次相同的音效,使其同时播放。

第二场比赛应该在第一场比赛结束之前开始。

相关问题是:

Playing two sounds simultaneously c#Play two sounds simultaneusly

我为 XNA 找到了这个类,它可以满足我的需求,但在 Metro 下不可用: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.audio.soundeffectinstance.aspx

【问题讨论】:

    标签: c# audio windows-8 microsoft-metro


    【解决方案1】:

    只需为每个音效创建一个单独的媒体元素。

    (不确定我是否每次都需要重新定位文件)

      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();
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2014-10-20
      • 2018-02-07
      • 1970-01-01
      • 2011-08-10
      • 1970-01-01
      • 1970-01-01
      • 2011-05-20
      • 1970-01-01
      相关资源
      最近更新 更多