Important alert: (current site time 7/16/2013 2:00:49 AM EDT)
 

VB icon

* Make Your Own *WAV* Player! *

Email
Submitted on: 4/24/1999
By: Matt Evans 
Level: Not Given
User Rating: By 5 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 64586
 
     This is the code to *PLAY*, *STOP*, and *LOOP* WAV files. Its really easy! even for a beginner! You can make your own WAV Player!
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :* Make Your Own *WAV* Player! *
'**************************************
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Public Const SND_SYNC = &H0
Public Const SND_ASYNC = &H1
Public Const SND_NODEFAULT = &H2
Public Const SND_MEMORY = &H4
Public Const SND_LOOP = &H8
Public Const SND_NOSTOP = &H10
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: * Make Your Own *WAV* Player! *
' Description:This is the code to *PLAY*, *STOP*, and *LOOP* WAV files. Its really easy! even for a beginner! You can make your own WAV Player!
' By: Matt Evans
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1654&lngWId=1'for details.'**************************************

Sub WAVStop()
Call WAVPlay(" ")
End Sub
Sub WAVLoop(File)
Dim SoundName As String
SoundName$ = File
wFlags% = SND_ASYNC Or SND_LOOP
X = sndPlaySound(SoundName$, wFlags%)
End Sub
Sub WAVPlay(File)
Dim SoundName As String
SoundName$ = File
wFlags% = SND_ASYNC Or SND_NODEFAULT
X = sndPlaySound(SoundName$, wFlags%)
End Sub


Other 11 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
4/28/1999 5:59:00 PMD.j. PsYcOtIc

I Keep Geting The Error Expected Type name?
Help!!
(If this comment was disrespectful, please report it.)

 
5/2/1999 5:56:00 PMjohn

comments: I THINK IT IS REALLY GREAT YOU POST STUFF UP FOR BEGGINERS AND AVENCE!
(If this comment was disrespectful, please report it.)

 
5/30/1999 1:26:00 PMkameron

it needs a type for the sndPlaySound function, so declare it 'as long'
i.e.:
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

(If this comment was disrespectful, please report it.)

 
7/11/1999 4:13:00 PMKOKO

HOW DO U STOP A WAV I CAN PLAY IT BUT NOT STOP IF U CAN HELP ME OUT EMAIL ME
(If this comment was disrespectful, please report it.)

 
8/3/1999 4:50:00 PMVbKid

No, this doesn't work. I have Vb6 and I have a much simpler code for it that works and this doesn't.
(If this comment was disrespectful, please report it.)

 
11/9/1999 2:32:00 PMJames

Yeah, got most of it to work except for the "stop" don't work at all. VbKid, share what you have! I'm using VB6 also.
(If this comment was disrespectful, please report it.)

 
1/2/2000 7:25:20 PMKunal Johar

'Here is my revision of this guy, put
'this in a module

Option Explicit
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Const SND_ASYNC = &H1
Public Const SND_NODEFAULT = &H2
Public Const SND_MEMORY = &H4
Public Const SND_LOOP = &H8
Public Const SND_NOSTOP = &H10
Public Sub StopSound() 'Run this when you want to stop noise
Call PlaySound(" ", False)
End Sub
Public Sub PlaySound(filename As String, repeat As Boolean)
'This Sub should be used to play midi/wav files
Dim wFlags%, X, SoundName As String
If repeat = True Then


SoundName$ = filename
wFlags% = SND_ASYNC Or SND_LOOP
X = sndPlaySound(SoundName$, wFlags%)
End If

If repeat = False Then

SoundName$ = filename
wFlags% = SND_ASYNC Or SND_NODEFAULT
X = sndPlaySound(SoundName$, wFlags%)
End If
End Sub


(If this comment was disrespectful, please report it.)

 
1/29/2000 6:18:17 AMMichael Barnathan

There's an easier way to revise code... you can post up new code from the author options(under submit). The sndplaysound function should be as long, I believe. The only code needed to play it is call sndplaysound(filename,1)
(If this comment was disrespectful, please report it.)

 
2/21/2000 8:50:09 PMBilly Bob

How do I make the sound stop the second I exit the program? I put the stop call in the Form_Unload sub, but it plays over again before it stops.
(If this comment was disrespectful, please report it.)

 
2/27/2000 3:02:05 PMalaa

please i need help for desigining
an Aritificial intellegence code under
vb.
(If this comment was disrespectful, please report it.)

 
11/10/2000 7:38:14 AMPaul Garfield

Thanks it worked first time in VB6. I used it to play the accompanying wav files from the jpg files on my digital camera. Great!
(If this comment was disrespectful, please report it.)

 
12/26/2000 11:22:12 AM Dim SoundName As String

Dim SoundName As String
SoundName$ = File
wFlags% = SND_ASYNC Or SND_NODEFAULT
X = sndPlaySound(SoundName$, wFlags%)

(If this comment was disrespectful, please report it.)

 
12/26/2000 11:23:22 AMAdrian

it work on me.
lol
(If this comment was disrespectful, please report it.)

 
2/10/2001 10:28:46 AMbeginner

hello,

from previous feedback it seems your article is useful but i am a total beginner and i can't fully appreciate it though i'd like to.
Would someone please take me step-by-step from openning VB6 to running the program.

I know this is a lot to ask but i would very much appreciate it.

thanks,

total beginner
(If this comment was disrespectful, please report it.)

 
4/19/2001 11:31:09 PMRob Loach

Dear Total Beginner,

I'm sorry, but I can't help you. But I do have advice for you:

DON'T START ON HARD THINGS! START ON EASY THINGS!

There ya go.

Cheers,
Rob Loach
(If this comment was disrespectful, please report it.)

 
12/1/2001 4:53:43 PMDe KoFfie

lol, it worked fine for me without any problem...
(If this comment was disrespectful, please report it.)

 
8/25/2002 2:56:49 PMranajit

kindly send vb source code via email
(If this comment was disrespectful, please report it.)

 
8/28/2002 1:08:28 PMDavid Fesliyan

I need help here, can someone email me telling me what the hell is a $ sign doing in the code? (warz123@hotmail.com)
(If this comment was disrespectful, please report it.)

 
9/27/2002 5:11:07 AM

kunal your code worked for me, thank you =)
(If this comment was disrespectful, please report it.)

 
10/8/2002 9:43:09 AM

The%2B%2524%2Bsign%252C%2Bafter%2Ba%2Bvariable%2Bname%2Bdeclaration%252C%2Bserves%2Bas%2 Ba%2B%2527%2BAS%2BLONG%2527%2Bstatement%252E
(If this comment was disrespectful, please report it.)

 
10/8/2002 9:46:40 AM

Eek! Garbage! This is the clean version:

Fesliyan,
The '&' token after variable name declaration serves as a 'A LONG' statement. There are several tokens, one for each default vartype.
(If this comment was disrespectful, please report it.)

 
1/3/2003 2:26:03 PM

There is no declared function. There should be a module with the following code: Declare Function Lib
(If this comment was disrespectful, please report it.)

 
1/28/2003 3:50:59 PMSoorya

why u kids start making the newbie a fool..
without API declarations... why you idio()s start writing codes in this great site.
(If this comment was disrespectful, please report it.)

 
3/5/2003 9:19:23 PM

Just load the windows media player ocx and use that control
(If this comment was disrespectful, please report it.)

 
5/11/2003 6:01:12 AMMark Steadman

Stop still doesn't work.
(If this comment was disrespectful, please report it.)

 
7/17/2003 10:55:02 AM

Public Sub StopSound()
' A working StopSound sub.
Dim X As String
X = sndPlaySound(0, SND_ASYNC)
End Sub
(If this comment was disrespectful, please report it.)

 
10/4/2003 3:03:22 PM

It on't work on my website, nothing works on it!! Does anyone know a SIMPLE wav/midi player code?!?!??!?!
(If this comment was disrespectful, please report it.)

 
10/26/2003 6:05:17 AMMuhammed Arif

it worked and worked really fine for me

nice peace of work buddy keep it up...



(If this comment was disrespectful, please report it.)

 
1/28/2004 5:17:16 AM

hi i am basanta i want to be the member of this site thank u
this is a good site
(If this comment was disrespectful, please report it.)

 
2/17/2004 11:42:53 PM

could anybody tell me that how can i make a project on IVRS(interactive voice response system....)the main problem i m having is how can i access the telephone .i have D/4 dialogic card installed in my PC.but with the help of which functions i can recognize the numbers dialed by user through his/her telephone.

(If this comment was disrespectful, please report it.)

 
4/17/2004 1:18:24 AM

I'm a student of University of Fisheries
(If this comment was disrespectful, please report it.)

 
1/12/2005 9:53:30 PMaaron

its wrong the api call thing is wrong you forgot to make it public!

write this in general|declarations

Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

(If this comment was disrespectful, please report it.)

 
6/21/2005 2:17:08 PM

oke
(If this comment was disrespectful, please report it.)

 
4/22/2009 3:41:27 AMapi....

dekhe nio...
(If this comment was disrespectful, please report it.)

 
4/29/2009 2:23:31 AMnguyen van trong

thanks!
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.