C#如何播放音频文件 http://expert.csdn.net/Expert/topic/2913/2913257.xml?temp=.6179926 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://expert.csdn.net/Expert/topic/2914/2914933.xml?temp=.9197199 C#中没有声音类。播放声音请参阅API!比如:[DllImport("Winmm.dll")]public static extern long PlaySound(string name,long module,long flag);播放声音using System;using System.Runtime.InteropServices;class musicplay{[DllImport("winmm.dll")]private static extern long mciSendString(string lpstrCommand,string lpstrReturnString,long length,long hwndcallback);public musicplay(string name){ filename=name; }public void play(){ t=mciSendString(@"open " + filename,m,0,0); t=mciSendString(@"play " + filename + @" wait",m,0,0); t=mciSendString(@"close " + filename,m,0,0);}private string filename;private string m=@" ";private long t;} class test{ static void Main(){ Console.WriteLine("请输入你要播放的歌曲的路径"); musicplay mpl=new musicplay(Console.ReadLine()); mpl.play(); Console.WriteLine("播放完毕,再见"); } } 我以前在VB里面用的方法,这里也可以用在工具栏添加/移除项,选COM组件,添加Microsoft MultiMedia Control 6.0然后把这个控件添加到你的FORM中去,你可以设置它的VISIBLE属性为FALSE写函数PlayMusic()private void PlayMusic(){ this.AxMMControl1.DeviceType = "Sequencer" '如果是WAV或AVI应该用"avivideo" this.AxMMControl1.FileName = "D:\University\Software\Media\main.mid" this.AxMMControl1.Command = "Open" this.AxMMControl1.Command = "play"}在FORM LOAD里调用PLAYMUSIC函数这样你的FORM启动起来就会自动播放音乐了.如果你想让它循环播放,在该控件的DONE方法里添加以下代码this.AxMMControl1.Command = "close"this.PlayMusic() 恳请高手赐教关于comboBox显示问题,本人小白。。。万盼回复~~~ GridViev 的列是程序里增加的,怎么在显示的值上加个超级链接 水晶报表的问题,刚在网上接触,图表显示有个疑问,请各位帮忙下 调试一天了,还是没找到解决办法 Web Service能不能返回typed dataset? 大侠看看修改系统时间的代码错在哪里! dataset合并后总是没数据 C#能编写游戏外挂吗? 怎样实现这样的聊天功能最好有用c#实现,ASP也可以。 如何得到外部应用程序的窗口大小? 旧话重提:关于cs结构中用户验证。 大家来帮忙,关于TreeView和ContextMenu.
比如:
[DllImport("Winmm.dll")]
public static extern long PlaySound(string name,long module,long flag);
播放声音
using System;
using System.Runtime.InteropServices;class musicplay{
[DllImport("winmm.dll")]
private static extern long mciSendString(string lpstrCommand,string lpstrReturnString,long length,long hwndcallback);
public musicplay(string name){
filename=name;
}
public void play(){
t=mciSendString(@"open " + filename,m,0,0);
t=mciSendString(@"play " + filename + @" wait",m,0,0);
t=mciSendString(@"close " + filename,m,0,0);
}
private string filename;
private string m=@" ";
private long t;
}
class test{
static void Main(){
Console.WriteLine("请输入你要播放的歌曲的路径");
musicplay mpl=new musicplay(Console.ReadLine());
mpl.play();
Console.WriteLine("播放完毕,再见"); }
}
在工具栏添加/移除项,选COM组件,添加Microsoft MultiMedia Control 6.0
然后把这个控件添加到你的FORM中去,你可以设置它的VISIBLE属性为FALSE
写函数PlayMusic()
private void PlayMusic()
{
this.AxMMControl1.DeviceType = "Sequencer" '如果是WAV或AVI应该用"avivideo"
this.AxMMControl1.FileName = "D:\University\Software\Media\main.mid"
this.AxMMControl1.Command = "Open"
this.AxMMControl1.Command = "play"
}
在FORM LOAD里调用PLAYMUSIC函数
这样你的FORM启动起来就会自动播放音乐了.
如果你想让它循环播放,在该控件的DONE方法里添加以下代码
this.AxMMControl1.Command = "close"
this.PlayMusic()