我正在尝试使用.NET Compact Framework从资源播放音频。我在我的应用程序中为资源属性添加了一个音频文件,并尝试使用以下示例资源文件参考代码...
SoundPlayer player = new SoundPlayer(Assembly.GetExecutingAssembly().
GetManifestResourceStream("blessedwav.wav"));
player.Play();
但是此代码不播放WAV声音。如何使用.NET Compact Framework 3.5播放资源音频文件?
答案 0 :(得分:7)
我得到了解决方案。此代码在.NET Compact Framework中运行良好:
// Convert a byte array to a stream
using (var audioStream = new MemoryStream(Properties.Resources.full_song_wav))
{
using (var player = new SoundPlayer(audioStream))
{
player.Play()
}
}
答案 1 :(得分:5)
试试这个:
//I added the file as a audio resource in my project
SoundPlayer player = new SoundPlayer(Properties.Resources.recycle);
player.Play();
我没有尝试使用.NET Compact Framework。但它在C#中为我工作。
答案 2 :(得分:1)
这应该适合你:
col-md-xx
确保您的命名空间高于Stream str = Properties.Resources.YourWaveSoundFile;
SoundPlayer plyr = new SoundPlayer(str);
plyr.Play();
。
答案 3 :(得分:0)
Resources.ResourceManager.GetStream("nudgeSound", Resources.Culture);
System.IO.Stream s = Resources.ResourceManager.GetStream("nudgeSound", Resources.Culture);
SoundPlayer player = new SoundPlayer(s);
player.Play();