日期:2014-05-17  浏览次数:21231 次

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