Tuesday, 18 August 2015

HOW TO PLAY SOUND IN VISUAL BASIC 6

Playing sound in VB6 is quite easier than any other application platform.
In this we need to use the SYSTEM DLL File WINMM.dll
This dll file is responsible in playing audios

Step 1 - First declare the following function...

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hmodule As Long, ByVal dwFlag As Long) As Long


Step 2 - Now declare the following variables

Private Const SND_APPLICATION As Long = &H80
Private Const SND_ALIAS As Long = &H10000
Private Const SND_ALIAS_ID As Long = &H110000
Private Const SND_ASYNC As Long = &H1
Private Const SND_FILENAME As Long = &H20000
Private Const SND_LOOP As Long = &H8
Private Const SND_MEMORY As Long = &H4
Private Const SND_NODEFAULT As Long = &H2
Private Const SND_NOSTOP As Long = &H10
Private Const SND_NOWAIT As Long = &H2000
Private Const SND_PURGE As Long = &H40
Private Const SND_RESOURCE As Long = &H40004
Private Const SND_SYNC As Long = &H0


Step 3 - Finally, where you wanted to play Sound
call the Function PlaySound with three parameters

eg.
PlaySound "E:\%FOLDERNAME%\FILENAME.wav", 0, SND_ASYNC


Here you have passed three arguements
- First you have passed the file location
- Second 0 is passed to ensure that you are using full File Location
- Third playing sound mode as ASYNCHRONOUS eg. SND_ASYNC ( You can also use other modes like SND_FILENAME,SND_LOOP etc)
  ASYNC means your application can produce sound in background

No comments:

Post a Comment