[英]C# Playing a sound in the background
private System.Media.SoundPlayer sp;
public Form1()
{
InitializeComponent();
sp = new System.Media.SoundPlayer(Properties.Resources.main);
}
private void Form1_Load(object sender, EventArgs e)
{
sp.Play();
}
main is a MP3 from resources...I get the following errors: *The best overloaded method match for System.Media.SoundPlayer.SoundPlayer(System.IO.Stream)' has some invalid arguments main是来自资源的MP3 ...我收到以下错误:* System.Media.SoundPlayer.SoundPlayer(System.IO.Stream)的最佳重载方法匹配'有一些无效的参数
and 和
*cannot convert from 'byte[]' to 'System.IO.Stream' *无法从'byte []'转换为'System.IO.Stream'
Microsoft do a great tutorial on this! 微软就此做了很棒的教程!
See: http://msdn.microsoft.com/en-us/library/windows/desktop/dd562692(v=vs.85).aspx 请参阅: http : //msdn.microsoft.com/en-us/library/windows/desktop/dd562692(v = vs。85).aspx
Good Luck. 祝好运。
Try this for wav. 试试这个wav。
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.Stream = Properties.Resources.main;
player.Play();
Or this for MP3: 或者这适用于MP3:
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = "main.mp3";
wplayer.Controls.Play();
If you want to play some SOUNDS in your Dot Net(C#,Vb.net) Form. 如果你想在你的Dot Net(C#,Vb.net)表格中播放一些声音。 Then write this code in your project and it will play a SOUND during execution.
然后在您的项目中编写此代码,它将在执行期间播放SOUND。 Remember you should have a ".wave" file for this purposes.
请记住,为此目的,您应该有一个“.wave”文件。
using System.Media; // write this at the top of the Form
SoundPlayer my_sound = new SoundPlayer("F:/aeroplantakeover.wave"); //put your own .wave file path
my_sound.Play();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.