Click to See Complete Forum and Search --> : sound other than BEEP


Alex122486
October 3rd, 2001, 09:39 PM
how can i add sounds such as .wav, .mp3,.mid,ect to my form? ive looked under the help files and all it says is BEEP.

Cimperiali
October 4th, 2001, 01:54 AM
to make an example:
http://codeguru.com/cgi-bin/bbs/wt/showpost.pl?Board=vb&Number=55331&page=2&view=collapsed&sb=5
(do not forget to give a rate to that helpful one)
;-)


Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater

Alex122486
October 8th, 2001, 08:00 AM
i got it to work and its great. but could you explain to me what the code is doing? using REM statements would help me out a lot. thanks :-)

Cimperiali
October 8th, 2001, 08:40 AM
'this is an api declare: you use to declare a function or sub which is
'inside a particular library which is related to your Os.
'This way, you can call an Os command:
public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (byval lpszSoundName as string, byval uFlags as Long) as Long
'Like functions and subs you can write, also Os functions and sub may require parameters of different kinds
'and functions may give back values of some kinds
'In this case, Api sndPlaySound expect two parms, the first as a string, the second a number (long, buty you
'will pass an exadecimal value) and will give back a long value.

'The following are Hexadecimal values for the second parameter. They will make the Api to act
'differently:
public Const SND_ASYNC = &H1 'sound a sound asyncronously: play and let do something else
'in meanwhile
public Const SND_LOOP = &H8 'loop -play continously
public Const SND_MEMORY = &H4 '...
public Const SND_NODEFAULT = &H2
public Const SND_SYNC = &H0

This is all the declaration you need to play a .wav file. Use code of this sort to play a file called "C:\test.wav" when command1 is clicked:

private Sub Command1_Click()
'if you do not need to process returned informations, you know you
'can call a function this way:
sndPlaySound "C:\test.wav", SND_ASYNC
'if you wanted to know returned value, you could call it this way:
dim retVar as long
retVar = sndPlaySound ("C:\test.wav", SND_ASYNC)
msgbox retVar
End Sub

by the way: from Api-guide (free tool you can download at http://www.allapi.net/)
The sndPlaySound function plays a waveform sound specified either by a filename
or by an entry in the registry or the WIN.INI file. This function offers a
subset of the functionality of the PlaySound function; sndPlaySound is being
maintained for backward compatibility.

and here how to use PlaySound:
'The PlaySound function plays a sound specified by the given filename,
'resource, or system event. (A system event may be associated with a sound in
'the registry or in the WIN.INI file.)

private Const SND_APPLICATION = &H80 ' look for application specific association
private Const SND_ALIAS = &H10000 ' name is a WIN.INI [sounds] entry
private Const SND_ALIAS_ID = &H110000 ' name is a WIN.INI [sounds] entry identifier
private Const SND_ASYNC = &H1 ' play asynchronously
private Const SND_FILENAME = &H20000 ' name is a file name
private Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound
private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
private Const SND_NODEFAULT = &H2 ' silence not default, if sound not found
private Const SND_NOSTOP = &H10 ' don't stop any currently playing sound
private Const SND_NOWAIT = &H2000 ' don't wait if the driver is busy
private Const SND_PURGE = &H40 ' purge non-static events for task
private Const SND_RESOURCE = &H40004 ' name is a resource name or atom
private Const SND_SYNC = &H0 ' play synchronously (default)
private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (byval lpszName as string, byval hModule as Long, byval dwFlags as Long) as Long
private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", byval 0&, SND_FILENAME Or SND_ASYNC
End Sub





Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater

Casholk
August 28th, 2003, 01:45 AM
Thank you for the coding it is useful for me.

now still have a problem that is how to used this to play mp3.? cos for the coding i found that only can play wav file. so i want to apply the play mp3 method to my form. can it make it.?

thank you..

Luthv
August 28th, 2003, 03:09 AM
You could also use MCI (Media Control Interface) commands and function to play Multimedia files, but MCI only defines the standard ways to handle multimedia files, the actual program that responds to this command might be Windows Media Player or some MPG player (depends on the file type and the machine configuration).

Check http://www.mentalis.org/agnet/apiguide.shtml and download their APIGuide application. Look in MCI section for some samples.

You may also check MSDN for complete reference on MCI