C# 如何用playsound()函数,按顺序播放多个WAV文件

解决方案 »

  1.   


    using System;
    using System.Runtime.InteropServices;
    using System.ComponentModel;
    public class clsPlaySound
    {
    protected const int SND_SYNC  = 0x0;
    protected const int SND_ASYNC  = 0x1;
    protected const int SND_NODEFAULT  = 0x2;
    protected const int SND_MEMORY  = 0x4;
    protected const int SND_LOOP  = 0x8;
    protected const int SND_NOSTOP  = 0x10;
    protected const int SND_NOWAIT  = 0x2000;
    protected const int SND_ALIAS  = 0x10000;
    protected const int SND_ALIAS_ID  = 0x110000;
    protected const int SND_FILENAME  = 0x20000;
    protected const int SND_RESOURCE  = 0x40004;
    protected const int SND_PURGE  = 0x40;
    protected const int SND_APPLICATION  = 0x80; [DllImport("Winmm.dll", CharSet=CharSet.Auto)]
    protected extern static bool PlaySound(string strFile, IntPtr hMod, int flag ); //播放声音函数
    //strSoundFile   --- 声音文件
    //bSynch         --- 是否同步,如果为True,则播放声音完毕再执行后面的操作,为False,则播放声音的同时继续执行后面的操作
    public static bool PlaySoundFile(string strSoundFile, bool bSynch)
    {
    if(!System.IO.File.Exists(strSoundFile))
    return false;
    int Flags;
    if(bSynch)
    Flags = SND_FILENAME | SND_SYNC;
    else
    Flags = SND_FILENAME | SND_ASYNC; return PlaySound(strSoundFile, IntPtr.Zero, Flags);
    }

    }//连续播放时
    for each(string file in files)
    {
    clsPlaySound.PlaySoundFile(file,true);
    }
      

  2.   


     [DllImport("winmm.dll")]
      public static extern bool PlaySound(string pszSound,int hmod,int fdwSound);
      public const int SND_FILENAME = 0x00020000;
      public const int SND_ASYNC = 0x0001; PlaySound("提示时奏幻想空间.WAV",0,SND_ASYNC|SND_FILENAME);
      

  3.   

    http://topic.csdn.net/u/20080924/21/80a3425a-f0d3-4e44-82cb-97e419eea85f.html
      

  4.   

    to gxingmin :
    我菜鸟,
    不知道怎么使用你这个函数,谢谢
      

  5.   

    to gxingmin : 
    让我怎么让它播放完这些文件后,又从头播放呢,也就是循环播放
      

  6.   

    //连续播放时,播完从头播
    for(i=0;i<files.Lengh;i++)
    {
       clsPlaySound.PlaySoundFile(files[i],true);
       if(i==file.Length)
        i==0;
    }
      

  7.   

    to gxingmin : 
    为什么只能循环一次,就停止播放了
      

  8.   

    to gxingmin : 
    为什么只能循环一次,就停止播放了
      

  9.   

    //连续播放时,播完从头播 
    for(i=0;i <files.Lengh;i++) 

      clsPlaySound.PlaySoundFile(files[i],true); 
      if(i==file.Length - 1) 
        i==0; 

      

  10.   

    to gxingmin : 
    现在又有一个问题,如何实现音乐的暂停与播放呢?不好意思又打扰你了,我找了很久好象没有暂停的函数,急!!!谢谢啦!参与有分!!,加分!
      

  11.   

    用线程的话,应该可以suppend了线程的吧
      

  12.   

    但是,用suppend的话,它不能立即停止当前播放的音乐,只有等到播放完一首音乐后,才暂停,而且在WINCE下是没有suppend
      

  13.   

    System.Media下有个SoundPlayer类,你试一试这个看看
      

  14.   

    我是在WINCE下编程的,WINCE下C#是没有这个”System.Media“的
      

  15.   

    Compact Framework 3.5带有SoundPlayer的。
      

  16.   

    啊,我用的是Compact Framework 2.0,是没有的
      

  17.   

    晕,最近我正在PocketPC上做一个录音/播放程序,不过我用的Mobile5.0,不是WinCE你可以引用OpenNETCF类库
    然后在OpenNETCF.Media.WaveAudio命名空间下有个Recorder类和Player类,分别控制录音和放音的,有暂停的方法