声音播放不播放任何捆绑窗户的声音PCM WAV文件 [英] SoundPlayer not playing any bundled windows sounds PCM wav files

查看:177
本文介绍了声音播放不播放任何捆绑窗户的声音PCM WAV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,我不能让声音播放类从System.Media从我的C播放任何WAV。我得到的是无声音:

In C# I cannot get SoundPlayer class from System.Media to play any wav from my C:\Windows\Media folder using the following code. All I get is no sound:

String filename = "C:\\Windows\\Media\\tada.wav";
SoundPlayer sp = new SoundPlayer(filename);
sp.Load();
sp.Play();

我已经检查了波形文件tada.wav有一个名为G点节目,告诉我的声音codeC是PCM音频。我没有收到任何编译器警告或错误,也没有当我运行程序产生的异常。我只是没有得到任何声音。我的发言是对的,我可以用Windows Media Player播放文件。

I have checked the wave file "tada.wav" with a program called "Gspot" that tells me the audio codec is "PCM Audio". I do not receive any compiler warnings or errors and there is no exceptions raised when I run the program. I just do not get any sound. My speakers are on, and I can play the file with Windows Media Player.

添加WAV作为项目资源没有任何区别。可能有人请帮我弄清楚,为什么我不能得到任何声音?

Adding the wav as a project resource does not make any difference. Could somebody please help me figure out why I cannot get any sound?

推荐答案

您使用此作为一个控制台应用程序中的main()方法的主体?该应用程序可能结束,从而切断其播放音频线。

Are you using this as the body of a main() method in a console application? The application is probably ending, thereby shutting down the thread which plays the audio.

我复制并粘贴您的code到主的一个新的Visual C#控制台应用程序。我添加了使用System.Text;在文件,编译的顶线,加大通过它,和它的工作。当我跑了(没有调试)我没有声音。

I copied and pasted your code into the main of a new "Visual C# Console Application". I added the "using System.Text;" line at the top of the file, compiled, stepped through it, and it worked. When I ran it (without debugging) I got no sound.

如果您添加一行:

System.Threading.Thread.Sleep(2000年);

System.Threading.Thread.Sleep(2000);

在调用播放(),应用程序将保持足够长的时间来播放音频。

After the call to Play(), the application will stay around long enough to play the audio.

这篇关于声音播放不播放任何捆绑窗户的声音PCM WAV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆