就象游戏连连看那样的程序。
要求:音乐是几首曲子,循环播放,可开可关
开发环境:vs2005
语言:C#
把关键的几行代码写出即可。

解决方案 »

  1.   

    .net没有内置的音乐支持,你只能借助于DirectX
    或者用老的MCI控件或WindowsAPI
      

  2.   

    背景音提示调用API,不过不怎么够用,也可以利用Window Media Player控件,右键单击工具箱 添加控件
    把控件拖在窗体上,在属性里边设置播放地址即可播放 http://zhidao.baidu.com/question/88441739
      

  3.   

    不想添加Window Media Player控件,不想在程序界面上显示出Window Media Player播放器,就象连连看那样只是有背景音乐而已.
      

  4.   

    看这个吧,用dx播放,不会有界面,效果应该也很不错,资源占用也小
    http://www.xland.com.cn/article/7/34/0601/7445.htm
      

  5.   

    把代码都帖出来了,有些不明白,红色的是我添加上去的。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();
       
       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("不能播放音乐");
       }
      }
     }
    }
    最后再问一句,如果两首曲子,如何循环播放?
      

  6.   


    不想在程序界面上显示出Window Media Player播放器,你把它隐藏了不就行了吗。程序运行的时候也是不显示的,用这个简单一些,用别的太麻烦。
      

  7.   

    using System.Media;
    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);