Link to home
Start Free TrialLog in
Avatar of a6106a
a6106a

asked on

How to play a wav file from VB

Please provide code that will have a Command button press play a Wav file.
It would be wonderful if a player didn't appear. I'd like this to be completely automatic.
Avatar of Vbmaster
Vbmaster

You can use the PlaySound API..

  'Do not use SND_RESOURSE or SND_FILENAME
  Private Const SND_ALIAS& = &H10000
  'Playsound returns immediately
  'Do not use SND_SYNC
  Private Const SND_ASYNC& = &H1
  'The name of a wave file.
  'Do not use with SND_RESOURCE or SND_ALIAS
  Private Const SND_FILENAME& = &H20000
  'Unless used, the default beep will
  'play if the specified resource is missing
  Private Const SND_NODEFAULT& = &H2
  'Fail the call & do not wait for
  'a sound device if it is otherwise unavailable
  Private Const SND_NOWAIT& = &H2000
  'Use a resource file as the source.
  'Do not use with SND_ALIAS or SND_FILENAME
  Private Const SND_RESOURCE& = &H40004
  'Playsound will not return until the
  'specified sound has played. Do not
  'use with SND_ASYNC
  Private Const SND_SYNC& = &H0

  Private Declare Function PlaySound& Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long)


You use it with code like..

Call PlaySound(Filename, 0, SND_FILENAME Or SND_ASYNC Or SND_NODEFAULT)
Avatar of a6106a

ASKER

vbmaster: Great. Works fine. Just need to know how to (from VB) stop the wav file from playing. As is, looks like I have to wait for it to stop itself.??
Avatar of a6106a

ASKER

VBMASTER: also , do you know if its possible to play an MP3 file from VB?
If so how please.
You can use the "Microsoft Activemovie Control" for playing MP3's. Check your Project -> Components, if you don't have it I guess you can download it somwhere on Microsoft's homepage..
ASKER CERTIFIED SOLUTION
Avatar of Vbmaster
Vbmaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial