我正在开发基于Silverlight的Windows 7应用程序。我无法找到一种在Windows 7手机上以编程方式播放音频文件的方法。过去几天以来,我一直在谷歌上搜索,但没有找到任何解决方案。C#中有一个SoundPlayer类,但我猜它在Windows 7手机上不可用。请问有人可以帮忙吗?
我正在开发基于Silverlight的Windows 7应用程序。我无法找到一种在Windows 7手机上以编程方式播放音频文件的方法。过去几天以来,我一直在谷歌上搜索,但没有找到任何解决方案。C#中有一个SoundPlayer类,但我猜它在Windows 7手机上不可用。请问有人可以帮忙吗?
<MediaElement
x:Name="sound"
Source="sound.wma"
AutoPlay="False" />
然后在代码后台:
sound.Play();
支持的格式为MP3和WMA。
使用Xna播放声音。虽然您可以从Silverlight应用程序中交叉引用Xna,但要播放声音文件,您需要遵循以下步骤:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio
// ...
Stream stream = TitleContainer.OpenStream("sounds/bonk.wav");
SoundEffect effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
祝您的应用开发一切顺利!
.tick
事件才能真正播放soundeffect
。最后,如果你在声音上使用mediaelement
而不是视频,它永远不会出现在你的页面上作为可见项。为什么这个答案被接受了呢? - Todd Main<Button>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<eim:PlaySoundAction Source="/Alarm1.wma" Volume="1"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:eim="clr-namespace:Microsoft.Expression.Interactivity.Media;assembly=Microsoft.Expression.Interactions"