using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Data;
using VBNET = Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System.Linq;
using System.Collections.Generic;

namespace Eval
{
   public static class modPlayWave
   {
      [DllImport("winmm.dll",EntryPoint="PlaySoundA")]
      private static extern int PlaySound(string lpszName,int hModule,int dwFlags);
      private const int SND_ASYNC = 0x1;     // Play Asyncronically
      private const int SND_SYNC = 0x0;     // Play Sincronically
      private const int SND_MEMORY = 0x4;     //  lpszSoundName points to a memory file, must be a string, converted to Unicode !
      private const int SND_PURGE = 0x40;     // Used to stop playin' WAVE
      private const int SND_NODEFAULT = 0x2;     //   silence not default, if sound not found
      private const int SND_FILENAME = 0x20000;     // lpszSoundName point to FileNAme
      private const int SND_LOOP = 0x8;     //   loop the sound until next sndPlaySound
      private const int SND_NOSTOP = 0x10;     //   don't stop any currently playing sound
      private const int SND_NOWAIT = 0x2000;     //   don't wait if the driver is busy
      //     Private Const SND_VALID = &H1F        '  valid flags          / ;Internal /
      //     Private Const SND_VALIDFLAGS = &H17201F    '  Set of valid flag bits.  Anything outside
      //                                     '  this range will raise an error
      [DllImport("winmm.dll")]
      private static extern int waveOutGetNumDevs();
      public enum APIWaveSourceTypeConstants
      {
         UseMemory = SND_MEMORY,
         UseFileName = SND_FILENAME
      }
      public enum APIWavePlayFlags
      {
         LoopSound = SND_LOOP,
         NoStopPreviousSound = SND_NOSTOP,
         NoWaitIfBusy = SND_NOWAIT,
         NoFlags = 0
      }
      // ***************************Wave Playing Code*************************************
      // Returns True if system can play wave
      public static bool CanPlayWaves()
      {
         return waveOutGetNumDevs() != 0;
      }
      // Plays Wave
      public static bool PlayWave(string Source,bool Async,APIWaveSourceTypeConstants SourceType,APIWavePlayFlags PlayType)
      {
         int lngFlags = 0;
         // Set Flags for PlaySound
         lngFlags = SND_NODEFAULT | SND_SYNC;
         if (Async)
         {
            lngFlags = lngFlags | SND_ASYNC;
         }
         lngFlags = lngFlags | ((int)SourceType);
         lngFlags = lngFlags | ((int)PlayType);
         // Play It !
         return PlaySound(Source,0,lngFlags) != 0;
      }
      public static bool StopPlayingWave()
      {
         PlaySound("",0,SND_PURGE);
         return false;
      }
   }
}
