把代码都帖出来了,有些不明白,红色的是我添加上去的。using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data;using DxVBLib; 1、如何添加这个引用?namespace 播放音乐 { public class Form1 : System.Windows.Forms.Form { private System.ComponentModel.Container components = null; public Form1() { InitializeComponent();
或者用老的MCI控件或WindowsAPI
把控件拖在窗体上,在属性里边设置播放地址即可播放 http://zhidao.baidu.com/question/88441739
http://www.xland.com.cn/article/7/34/0601/7445.htm
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;using DxVBLib; 1、如何添加这个引用?namespace 播放音乐
{
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null; public Form1()
{
InitializeComponent();
directX=new DirectX7Class();
performance=directX.DirectMusicPerformanceCreate();
composer=directX.DirectMusicComposerCreate();
loader=directX.DirectMusicLoaderCreate(); performance.Init(null,0);
performance.SetPort(-1,4); 2、这句是什么意思,参数是何含义?
performance.SetMasterAutoDownload(true); //chordMap=loader.LoadChordMap(@"F:游戏音乐(mid)GAME01FM.MID");3、括号中好象是音乐文件和路径名,但(mid)又是怎么回事?
try
{
chordMap=loader.LoadChordMap("CHORDMAP.CDM");4、括号中的参数好象又是一个文件,这是什么文件?
}
catch (Exception)
{
MessageBox.Show("Could not load ChordMap."+"Please ensure that CHORDMAP.CDM is"+"in the directory of this exectutable.");
}
} private DirectX7 directX;
private DirectMusicChordMap chordMap;
private DirectMusicComposer composer;
private DirectMusicPerformance performance;
private DirectMusicSegment segment;
private DirectMusicLoader loader;
private System.Windows.Forms.Button button1;
private DirectMusicStyle style;
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
style=loader.LoadStyle(@"F:游戏音乐(mid)GAME01FM.MID");
segment=composer.ComposeSegmentFromShape(style,64,0,2,false,false,chordMap);
composer.AutoTransition(performance,segment,(int)CONST_DMUS_COMMANDT_TYPES.DMUS_COMMANDT_FILL,(int)CONST_DMUS_COMPOSEF_FLAGS.DMUS_COMPOSEF_IMMEDIATE,chordMap);5、这一堆大写字母加下划线是什么意思?
}
catch(Exception)
{
MessageBox.Show("不能播放音乐");
}
}
}
}
最后再问一句,如果两首曲子,如何循环播放?
不想在程序界面上显示出Window Media Player播放器,你把它隐藏了不就行了吗。程序运行的时候也是不显示的,用这个简单一些,用别的太麻烦。
using System.IO;
SoundPlayer music = new SoundPlayer();
music = new SoundPlayer(Directory.GetCurrentDirectory() + "\\a.wav");
music.Play();[DllImport("winmm.dll")]
private static extern bool PlaySound( string szSound, IntPtr hMod, PlaySoundFlags flags );
using System.Runtime.InteropServices;
public static uint SND_ASYNC = 0x0001;
public static uint SND_FILENAME = 0x00020000;
[DllImport( "winmm.dll ")]
public static extern uint mciSendString(string lpstrCommand,
string lpstrReturnString, uint uReturnLength, uint hWndCallback);