
这样可以实现:
添加可以添加using System.Media;名称空间,然后写如下代码:
SoundPlayer sp = new SoundPlayer("音乐文件路径")//应该是wav格式的音频
sp.PlayLooping()//循环播放
sp.Play()//播放单次
sp.Stop()//停止
如需要播放其他格式的,则需要其他方法,
使用资源编辑器将音乐文件添加进去,程序运行的时候将文件释放出即可 菜单:外接程序、外接程序管理器,找到资源编辑器,加载即可,在工具菜单就能找到资源编辑器了将文件添加进去后 在form_load事件中Private Sub Form_Load()Dim tmp() As Byte
tmp = LoadResData(101, "custom") Open App.Path &"\test.mp3" For Binary As #1 Put #1, , tmp
Close
End Sub然后就能使用该test.mp3文件播放了(黑体字部分你可以自行修改)
1:使用控件Microsoft MutileMedia Control Version 6.0,可在Vs.net中添加此控件. 取名为player. '播放背景音乐 player.FileName = Application.StartupPath "\Music\GameMain.mid" player.Command = "Open" player.Command = "Play" 这种方法我测试过就可以播放wma和wmv格式的音乐文件,而且在播放wmv的时候会新建窗口 2.你可以用 directx 9 的托管DirectX.AudioVideoPlayback.DLL里面有个类命,你可以在C:的Microsoft.net的文件夹里面找到这个文件,用这个类Audio,用来播放音 乐很方便, Audio v=Audio(".mp3")v.ending +=new .....//添加事件处理函数! 在他的事件处理函数里可以写 v.open("声音文件名!") v.play()详细的可以自己处理一下就行了! 3.可以使用SoundPlayer.PlaySync 方法 来异步加载文件并播放. -------------------------------------------------------------------------------- 如何在Winform环境下,给窗体添加背景音乐? 比如: private SoundPlayer Player = new SoundPlayer()//首先NEW一个播放器 private void loadSoundAsync() { // Note: You may need to change the location specified based on // the location of the sound to be played. this.Player.SoundLocation = " http://www.tailspintoys.com/sounds/stop.wav"this.Player.LoadAsync()} private void Player_LoadCompleted( object sender, System.ComponentModel.AsyncCompletedEventArgs e) { if (this.Player.IsLoadCompleted) { this.Player.PlaySync()} } //比如这是在本地找的背景 this.axWindowsMediaPlayer1.URL = @"F:\MS\09 老鼠愛大米.mp3"this.axWindowsMediaPlayer1.Visible=false 本文来自CSDN博客,转载请标明出处: http://blog.csdn.net/alex_xhui/archive/2009/11/02/4757073.aspx欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)