我的工作Windows7的基础的应用程序开发力。我没有能够找到一种方法发挥一个音频文件,在windows7手机编程。我已经google搜索,因为过去几天,但我不能让任何解决方案。有一类SoundPlayer在C#但我想它不适用于Windows7话。任何人都可以请有帮助吗?

有帮助吗?

解决方案

使用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();

所有最适合您的应用程序的开发!

其他提示

你可以把一个MediaElement XAML中的看法:

<MediaElement 
    x:Name="sound" 
    Source="sound.wma" 
    AutoPlay="False" />

然后在代码隐藏:

sound.Play();

支持格式的MP3和医.

您需要使用的MediaElement。这里的一个教程

http://create.msdn.com/en-US/education/快速入门/ Video_and_Audio

如何简单地使用内置的行为?

<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"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top