ÕâÀïÊÇչʾ×î¼òµ¥µÄDirectX²¥·ÅÉùÒôµÄÀý×Ó£¬ÎÒ¾¡Á¿Ê¡ÂÔÁËÎ޹صĴúÂë¡£×îºóµÄ´úÂëÖ»ÓÐ19ÐУ¬¹»¼òµ¥ÁË°É£¿
×¼±¸¹¤×÷£º
1.°²×°ÁËDirectX SDK£¨ÓÐ9¸öDLLÎļþ£©¡£ÕâÀïÎÒÃÇÖ»Óõ½MicroSoft.DirectX.dll ºÍ Microsoft.Directx.DirectSound.dll
2.Ò»¸öWAVÎļþ¡££¨ÕâÑùµÄÎļþ±È½ÏºÃÕÒ£¬ÔÚQQµÄĿ¼Àï¾Í²»ÉÙ°¡¡£ÕâÀï¾Í²»¶à˵ÁË¡££©Ãû×Ö½ÐSND.WAV£¬·ÅÔÚ×îºóÄ¿±ê³ÌÐòµÄͬ¸öĿ¼ÏÂÃæ
¿ªÊ¼Ð´³ÌÐòÀ²¡£Ëæ±ãÓøöUltraEdit¾ÍºÃÁË¡£
1.ÒýÈëDirectX µÄDLLÎļþµÄÃû×ֿռ䣺
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;
2.½¨Á¢É豸¡£ÔÚÎÒÃǵ¼ÈëµÄMicrosoft.DirectX.DirectSound¿Õ¼äÖУ¬ÓиöDeviceµÄÀà¡£Õâ¸öÊDZíʾϵͳÖеÄÉùÒôÉ豸¡£
Device dv=new Device();
3.ÉèÖÃCooperativeLevel¡£ÒòΪWindowsÊǶàÈÎÎñµÄϵͳ£¬É豸²»ÊǶÀÕ¼µÄ£¬ËùÒÔÔÚʹÓÃÉ豸ǰҪΪÕâ¸öÉ豸ÉèÖÃCooperativeLevel¡£µ÷ÓÃDeviceµÄSetCooperativeLevel·½·¨£ºÆäÖУ¬µÚÒ»¸ö²ÎÊýÊÇÒ»¸öControl£¬µÚ¶þ¸ö²ÎÊýÊǸöö¾ÙÀàÐÍ¡£
ÔÚÕâ¸ö³ÌÐòÖУ¬ControlÎÒËæ±ãŪÁ˸ö²ÎÊýÈû½øÈ¥£¨ºÜº¹°É£¡£©¡£Èç¹ûÔÚwindows³ÌÐòÖУ¬¿ÉÒÔÓÃthis´úÌæ¡£µÚ¶þ¸ö²ÎÊý¾ÍÊÇÓÅÏȼ¶±ð£¬ÕâÀï±íʾÓÅÏȲ¥·Å¡£
dv.SetCooperativeLevel((new UF()),CooperativeLevel.Priority);
4.¿ª±Ù»º³åÇø¡£¶ÔÓÚÉÏÃæµÄÉùÒôÉ豸£¬ËûÓиö×Ô¼ºµÄ»º³åÇø£¬½ÐÖ÷»º³åÇø¡£ÏµÍ³ÖУ¬Ò»¸öÉ豸ÓÐΨһµÄÖ÷»º³åÇø¡£ÓÉÓÚwindowsÊǶàÈÎÎñ£¨ÓÖÊÇÕâ¸ö£¡£©£¬ËùÒÔ¿ÉÒÔÓм¸¸ö³ÌÐòͬʱÀûÓÃÒ»¸öÉ豸²¥·ÅÉùÒô£¬ËùÒÔÿ¸ö³ÌÐò¶¼×Ô¼º¿ª±ÙÒ»¸ö¶þ¼¶»º³åÇø£¬·Å×Ô¼ºµÄÉùÒô¡£
ϵͳ¸ù¾Ý¸÷¸ö³ÌÐòµÄÓÅÏȼ¶±ð£¬°´ÕÕÏàÓ¦µÄ˳Ðò·Ö±ðÈ¥¸÷¸ö¶þ¼¶»º³åÇøÖжÁÈ¡ÄÚÈݵ½Ö÷»º³åÇøÖв¥·Å¡£ÕâÀÎÒÃÇΪSND.WAV¿ª±ÙÒ»¸ö»º³åÇø¡£
ÆäÖУ¬µÚÒ»¸ö²ÎÊý±íʾÎļþÃû£¨Éµ¹Ï¶¼¿´³öÀ´ÁË£¡£©£¬µÚ¶þ¸ö¾ÍÊÇÐèҪʹÓõÄÉ豸¡£
SecondaryBuffer buf=new SecondaryBuffer(@"snd.wav",dv);
5.½ÓÏÂÀ´¾Í¿ÉÒÔ²¥·ÅÀ²¡£µÚÒ»¸ö²ÎÊý±íʾÓÅÏȼ¶±ð£¬0ÊÇ×îµÍµÄ¡£µÚ2¸ö²ÎÊýÊDz¥·Å·½Ê½£¬ÕâÀïÊÇÑ»·²¥·Å¡£
buf.Play(0,BuffERPlayFlags.Looping);
6.ÓÉÓÚÃüÁîÐгÌÐòûÓÐÏûϢѻ·£¬Ö´ÐÐÍê´úÂë¾ÍÍ˳öÁË£¬ËùÒÔ£¬ÎÒÃÇÐèÒªÔÝÍ£³ÌÐò¡£
Console.Read();
7.¹Ø¼üµÄ²¿·ÖÒѾÍêÁË£¬ÕâÀïÖ»Êǽ»´úһϸղŵÄÄǸöµ¹Ã¹µÄnew UF() ÊÇʲô¶«Î÷¡£Õâ¸öÍêÈ«ÊÇΪÁËÓ¦¸¶SetCooperativeLevelµÄ²ÎÊýÒªÇó¡£ÎÒ²»ÖªµÀÕâÑù×öÓÐʲô¸½×÷Ó㨸÷λÈç¹ûÒò´Ë°ÑÉù¿¨ÉÕÁË¡¡¡¡£©
class UF:Form{}
8.´úÂëдÍêÀ²~~~¡£ÏÂÃæ¿ÉÒÔ±àÒëÁË£¬ÕâÀï±àÒë±È½Ï¸´Ôӵ㡣
csc /r:directX\MicroSoft.DirectX.dll;directX\Microsoft.Directx.DirectSound.dll dxsnd.cs
ÕâÀÎÒ°Ñ2¸öDLLÎļþ·ÅÔÚµ±Ç°Ä¿Â¼µÄdirectxĿ¼Ï£¨Õâ¸öÊÇÎÒ×Ô¼º½¨µÄ£¬ÄãÖ»ÐèÒªÖ¸³öÕâ2¸öÎļþµÄλÖþͿÉÒÔÁË¡££©
˳±ã°ÑÎÒµÄĿ¼½á¹¹ËµÃ÷һϣº
|--dxsnd.cs
|--snd.wav
|--
|
|--MicroSoft.DirectX.dll
|--Microsoft.Directx.dll
ÏÂÃæÊÇÍêÕû´úÂ룺
//dxsnd.cs
using System;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;
using System.Windows.Forms;
namespace test1
{
¡¡class test
¡¡{
¡¡¡¡public static void Main(string [] args)
¡¡¡¡{
¡¡¡¡¡¡Device dv=new Device();
¡¡¡¡¡¡dv.SetCooperativeLevel((new UF()),CooperativeLevel.Priority);
¡¡¡¡¡¡SecondaryBuffer buf=new SecondaryBuffer(@"snd.wav",dv);
¡¡¡¡¡¡buf.Play(0,BufferPlayFlags.Looping);
¡¡¡¡¡¡Console.ReadLine();
¡¡¡¡}
¡¡¡¡class UF:Form{}
¡¡}
}