Option Strict Off
Option Explicit On
Imports System.Linq
Imports System.Collections.Generic
Namespace Eval
   Public Module modPlayWave
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String,ByVal hModule As Integer,ByVal dwFlags As Integer) As Integer
   Private Const SND_ASYNC As Integer = &H1 'Play Asyncronically
   Private Const SND_SYNC As Integer = &H0 'Play Sincronically
   Private Const SND_MEMORY As Integer = &H4 ' lpszSoundName points to a memory file, must be a string, converted to Unicode !
   Private Const SND_PURGE As Integer = &H40 'Used to stop playin' WAVE
   Private Const SND_NODEFAULT As Integer = &H2 '  silence not default, if sound not found
   Private Const SND_FILENAME As Integer = &H20000 'lpszSoundName point to FileNAme
   Private Const SND_LOOP As Integer = &H8 '  loop the sound until next sndPlaySound
   Private Const SND_NOSTOP As Integer = &H10 '  don't stop any currently playing sound
   Private Const SND_NOWAIT As Integer = &H2000 '  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
Private Declare Function waveOutGetNumDevs Lib "winmm.dll" As Integer
   Public Enum APIWaveSourceTypeConstants
      UseMemory = SND_MEMORY
      UseFileName = SND_FILENAME
   End Enum
   Public Enum APIWavePlayFlags
      LoopSound = SND_LOOP
      NoStopPreviousSound = SND_NOSTOP
      NoWaitIfBusy = SND_NOWAIT
      NoFlags = 0
   End Enum
   '***************************Wave Playing Code*************************************
   'Returns True if system can play wave
   Public Function CanPlayWaves() As Boolean
      CanPlayWaves = waveOutGetNumDevs() <> 0
   End Function
   'Plays Wave
   Public Function PlayWave(ByVal Source As String,Optional ByVal Async As Boolean = True,Optional ByVal SourceType As APIWaveSourceTypeConstants = APIWaveSourceTypeConstants.UseFileName,Optional ByVal PlayType As APIWavePlayFlags = APIWavePlayFlags.NoFlags) As Boolean
      PlayWave = False
      Dim lngFlags As Integer = 0
      'Set Flags for PlaySound
      lngFlags = SND_NODEFAULT Or SND_SYNC
      If (Async) Then
         lngFlags = lngFlags Or SND_ASYNC
      End If
      lngFlags = lngFlags Or SourceType
      lngFlags = lngFlags Or PlayType
      'Play It !
      PlayWave = PlaySound(Source,0,lngFlags) <> 0
   End Function
   Public Function StopPlayingWave() As Boolean
      StopPlayingWave = False
      PlaySound(Constants.vbNullString,0&,SND_PURGE)
   End Function
   End Module
End Namespace
