winform窗体添加背景音乐(三种方式)

winform窗体添加背景音乐(三种方式)

 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;

转载于:https://www.cnblogs.com/baishiying/archive/2012/08/29/2662114.html

 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;

猜你喜欢

转载自blog.csdn.net/weixin_33895604/article/details/93439977