读书人

c#怎么添加背景音乐

发布时间: 2012-09-29 10:30:01 作者: rapoo

c#如何添加背景音乐
自己制作了个窗体应用程序,我想让他在窗体打开时就添加背景音乐。
不知道用什么类的什么方法可以为程序添加音乐,要加载音乐播放控件吗?

[解决办法]

C# code
string FilePath = listView.SelectedItems[0].Tag.ToString();//视频的初始路径           axWindowsMediaPlayer_Video.URL = FilePath;//axWindowsMediaPlayer是播放器控件名字          axWindowsMediaPlayer_Video.Ctlcontrols.play();
[解决办法]
C# code
工具箱右击 选择项 COM组件 找到window media player  添加 然后在窗体添加这个控件            this.axWindowsMediaPlayer1.URL = "G:\\film\\你若成风.mp3";           this.axWindowsMediaPlayer1.Ctlcontrols.play();//播放            this.axWindowsMediaPlayer1.Ctlcontrols.pause();//暂停
[解决办法]
探讨
引用:

怎么只能放音乐呀!!!如果放视屏文件怎么办呀???
this.axWindowsMediaPlayer1.URL = "G:\\film\\你若成风.mp3";\\把路径改成视频路径不就好了

[解决办法]
HTML code
<SCRIPT type=text/javascript>var IsOpenMusic = true;function MusicOperate(){  var obj = document.getElementById("music");  var wma = document.getElementById("wma");  if(IsOpenMusic == true)  {  wma.stop();  obj.innerHTML = "背景音乐 (开)";  IsOpenMusic = false;  }  else  {  wma.play();  obj.innerHTML = "背景音乐 (关)";  IsOpenMusic = true;  }}</SCRIPT><OBJECT id=Object1 style="DISPLAY: none" type=application/x-mplayer2    name=wma><PARAM NAME="src" VALUE="<%=strMu %>">  <PARAM NAME="autostart" VALUE="true"><PARAM NAME="controller" VALUE="true"></OBJECT>  <SPAN id=music style="CURSOR: hand"    onclick=MusicOperate()>背景音乐 (关)</SPAN>
[解决办法]
using System.Media;
using System.IO;
SoundPlayer music = new SoundPlayer();
music = new SoundPlayer("");
music.Play();

[DllImport("winmm.dll")]
public static extern long PlaySound(String fileName,long a,long b);

[DllImport("winmm.dll")]
public static extern long mciSendString(string lpstrCommand,string lpstrReturnString,long length,long hwndcallback);
public static void PlayMusic(string p_FileName)
{
try
{
mciSendString(@"close "+p_FileName ,"",0,0);
mciSendString(@"open " + p_FileName,"",0,0);
mciSendString(@"play " + p_FileName ,"",0,0);
}
catch
{
}
}

读书人网 >C#

热点推荐