?
Solved

How to play a wav file from VB

Posted on 2000-01-19
5
Medium Priority
?
134 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:a6106a
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2368663
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)
0
 

Author Comment

by:a6106a
ID: 2373919
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.??
0
 

Author Comment

by:a6106a
ID: 2373920
VBMASTER: also , do you know if its possible to play an MP3 file from VB?
If so how please.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2373952
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..
0
 
LVL 7

Accepted Solution

by:
Vbmaster earned 120 total points
ID: 2373966
Use the following code to stop the wav file from playing..

  Call PlaySound("", 0, 0)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question