Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




'PlaySound' Function And Sound Events


Hello,
I'm developing a program in VB6 where I need do play a wave file assinchronously and be 'advised' when the execution of the sound has finished (receiving an event).

P.S.: Now I'm using the function PlaySound (winmm.lib) to play the wave file, but I donīt find a way to check if the sound have already been played entirelly or not.

Any idea on how to do that?
Thanks!




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Playing Sound With PLAYSOUND API
I want to play a sound on my form with the playsound API. I would like the sound to play once and then stop. The sound file is called ohmagod.wav and it is located on my desktop.
I know how to declare it.

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

That is all I Have so far though.
Could someone please give me the code to do it.
I have been to this site but it is too confuduling
http://www.mentalis.org/apilist/PlaySound.shtml

Thanks in advanced

PlaySound Function
Hi all,

i used The PlaySound API function to play .WAV extension sound files,,but how do i use the same function to STOP playing the file..thanx

PlaySound Function
i had trouble using playsound function, my game needs to keep playing sounds, and i did use snd_nostop and snd_nowait, however the problem is that when i try to play a lot of them almost at the same time, with no waits, some sounds are not played.... is it just my computer not able to handle that many channels or do i have to do something to playsound

thanks

Sound Events
i know how to play sounds using the api. BUT!! how do i call a sound event, as in the ones that are stored in the sound scheme in the sounds control panel?

Cheers
Craig

Sound Activated Events
Hi guys

I am in the process of writing a very large project that controls thearter lights via an interface box. All is going well, but I am now looking at what is refered to in the industry as 'Sound to Light' What I require is to be able to trigger a sub routine when a certain input level of sound is taken on the sound cards input, but only when the peek occures in a certain frequency range e.g. if a bass beat occures then it should trigger one peice of code, if a trebble peek occures then another peice of code is executed.

Is this posiable?

Many thanks

Sound Activated Events ?
I am interested in creating an event to trigger some code. The event would
be when (any?) sound comes in via the line in port of a sound card. Can
anyone direct me to some information about this? I was told by a few people
that there are some libraries already created to take care of a sound
activated event.. but they are more used for VOX and voice recognition.

Chris

Direct Sound Function
Is it possible to use the direct sound function or any other sound function on a computer that does not have direct x?

My problem is, when i try to run a program i have written at home, i have sound, however, when i use the computers at school, i get an error and the following line is highlighted:

"Set DS = DX.DirectSoundCreate(DSEnum.GetGuid(cboDevices.ListIndex + 1))"

Function , Method , Events
What's the deference between them ?

Sleep Function Tthat Allows Events ?
I know about sleep , but there is better sleep function i thikn its sleepex, anybody got an example ?

Is It Possible To Activate A Function When A Specific Sound Is Outputed Via Speakers?
As the title says, i want to create a listener to detect specified sound outputs

I'm pretty sure it possible with DirectSound, but not sure how - any ideas?

Access 97 Function Calls From Events Stop Working.
Hi Folks

I have a very odd one

I have an Access 97 MDB application.  It has all been working fine for over a year - upwards of 10 users.
Suddenly one user starts getting errors.
On investigating I find that event procedures and calls from code are working fine.
What is not working is calls to functions directly from events. They give the "Bloggs.MDB can't find the Macro or Function blah blah blah" as if the name was misspelt.  (It is not !)  Every other user is working fine.  I have got a fresh copy of the mdb.  I have recompiled the modules the database on the machine in question.
Then I notice his Access is SP1  - Putting on SP2 fixes everything - he is fine - it all works - until he restarted next morning when the problem came back.
I have tried a noddy database written from scratch on his system and it shows the same faults - seems like it is Access that has the problem not the MDB.
If it is relevant he is using Windows ME - everyone else has Windows 98 I think.

HELP PLEASE!!!

Ian J


How To Connect Events Of Multiple Objects To One Event Handling Function?
Hi, Gurus
Please help me with this. I've been doing research for a few days but haven't got a solution. In my case, I need to create several objects of the same type. The object generates a few events need to be handled. I need to create the objects dynamically at runtime.

Now is my question. How can I connect the events with the event handing functions using WithEvents? With WithEvents, I can connect the event of a particular object with a function at design time. But I need to create the object at runtime.

I know with control array I can trap events generated by multiple objects with only one handler. (sorry, I don't know how to name the variable declared by WithEvents) But it seems to me control array only handle activex components. May I create control array at runtime? I am quite confused.

Sorry for so many questions. I was mainly working in C++ before and haven't been adjusted right for VB yet. But I have to work out the project on my own with tight schedule. If someone can help me out, I really appreciate that.

Sound Event (When Some Sound Arrives In Sound CarD)
Hello,

   I need to be notified when any sound comes into Sound Card. Any idea?

   The theme is that there could be speaker volume high and user may not be playing any sound (audio etc). At that moment, if some windows alert or some other sound like this arrives, we need to play that at low volume so that user do not get frustrated. Also, if the speaker volume is high and no sound is being played, there could be a "hummmmmmmmmmmm" sound in speakers which could be frustrating. So I am going to write some application which may avoid such things.

   Thank you in advance.

   Sameers

Sameers (theAngrycodeR)
DevelopersINN
Need to be reminded for your Outlook Emails? Check Outlook Personal Assistant

Playsound
Hi, I've been reading about playsound, and was wondering if someone could show me a basic example on how to use it, such as just playing a sound you point it to? Thanks.

Little Bug With MCI PlaySound
Good Day,
I am using the MCI sound API.
Works great, but sometimes, when I ask the program to stop playing a sound and immediately after, I ask for a new sound to be played, it plays the old sound, as if the instruction was asked too fast for the APi to be able to handle it ?

Any hints ?
Many Thanks

PlaySound
Code:
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_ASYNC = &H1

PlaySound App.Path & "demons.wav", ByVal 0&, SND_ASYNC

This doesnt work... where is the problem...

Playsound Api (help)
trying to get my chat program to play a sound when someone send a message, please dont move this to communications cause theres nothing wrong with the actual chatting. i made a module and put this code into it

Code:
Public Declare Function PlaySound Lib "winmm.dll" Alias _
"PlaySoundA" (ByVal lpszName As String, ByVal _
hModule As Long, ByVal dwFlags As Long) As Long
i got it from that api website, and when data is received i have it to play a sound using this

Code:
PlaySound "C:Program filesAim95soundsimsend.wav", ByVal 0&, [b]SND_FILENAME[/b] Or [b]SND_ASYNC[/b]
however it says that the bolded vairables are not delcared. and im sorta stuck
can someone gimme a solution plz?

Playsound API
Hey, can someone give me a piece of code that describes the playsound api and how to call it?
and also, how would you play multiple sounds?

PlaySound
I'm having trouble using the PlaySound API. I want my file called App.Path & "80sSong.wav" to be played until the game stops. Even if the song ends, play it again. I've tried a lot of combinations but I can't get it. I know this is easy so could you please just tell me that ONE line of code to make it play repeatedly until the program ends? Or just the SND flags that I need. I appreciate any help in advance.

Playsound
Hi there

I already researched ďPlaySoundĒ. But I didnít find out how to make the computer run a sound without stopping the previous, so that the sounds are mixed. Any ideas?

PlaySound
Quote:





Originally Posted by Myth



Code:
Public Declare Function PlaySound Lib "winmm.dll" Alias _
"PlaySoundA" (ByVal lpszName As String, ByVal _
hModule As Long, ByVal dwFlags As Long) As Long
Public Const SND_ASYNC = &H1 ' play asynchronously
Public Const SND_FILENAME = &H20000 ' name is a file name

Code:
PlaySound App.Path & "imsend.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
works perfectly for me





why is it then that when i try this all i get is a beep when the form loads

PlaySound API
Hi,
My motherboard seems not to be compatible with the api Beep because I can't hear a sound,while it worked with my old PC.
So I'm trying to figure out how to use playsound but the first parameter is a
string and I don't have a clue on what to use for that string.
I just need to play simple beeps that reproduce basic music tones (a,b,c...)
Thanks for your help.
Horazio.

PlaySound
Trying to use PlaySound API and I still get a windows beep in the following subroutine:

my declarations


VB Code:
Private Const SND_APPLICATION = &H80         ' look for application specific associationPrivate Const SND_ALIAS = &H10000     ' name is a WIN.INI [sounds] entryPrivate Const SND_ALIAS_ID = &H110000    ' name is a WIN.INI [sounds] entry identifierPrivate Const SND_ASYNC = &H1         ' play asynchronouslyPrivate Const SND_FILENAME = &H20000     ' name is a file namePrivate Const SND_LOOP = &H8         ' loop the sound until next sndPlaySoundPrivate Const SND_MEMORY = &H4         ' lpszSoundName points to a memory filePrivate Const SND_NODEFAULT = &H2         ' silence not default, if sound not foundPrivate Const SND_NOSTOP = &H10        ' don't stop any currently playing soundPrivate Const SND_NOWAIT = &H2000      ' don't wait if the driver is busyPrivate Const SND_PURGE = &H40               ' purge non-static events for taskPrivate Const SND_RESOURCE = &H40004     ' name is a resource name or atomPrivate 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


__________________________________________________


VB Code:
Private Sub cmdMain_Click()PlaySound (App.Path & "gunshot.wav"), ByVal 0&, SND_FILENAME Or SND_ASYNCEnd Sub


I don't get any errors but I don't get the sound either. Just the default XP beep.

Any ideas anyone?

Playsound API
I use this API funcion to play sounds while my app is running.
But the program pauses its execution until the sound stops playing. How can i change that?
I want to play a sound without my app being paused.
Is this possible, or is there another way than the PlaySound API ?
thanks for any help

PlaySound
Hello,

I use the API function "PlaySound" to play wav sound in my project

as mentioned in MSDN:
to play sound I write: Call PlaySound(strWavFile, 0&, SND_ASYNC)
to stop playing : Call PlaySound("", 0&, SND_PURGE)

but the last statement does nothing with Windows NT, while it works well with Windows 98.

Anyone can help me solving this problem?

Edited by - bmarzouk on 9/10/2001 2:13:10 PM

PlaySound API
I am using playsound api call to invoke .wav file from my application. is there is any way to find out whether my sound file is running or finished ?
thanks in advance
sachin

PlaySound
I have made a vb application that plays a sound using the playsound32 function from winmm.dll, when something critical occurs. The problem with using this function is that it won't play a sound if I'm watching/hearing something else with realplayer or windows media player. Is there any way to override the current sound played so the critical sound can play? A visual warning is not good eneough.

PlaySound
I am trying to use Playsound to play sounds in my game but am encountering several difficulties. First off, the game tends to pause when beginning to play the sound for some reason. Also, even though i am using ASYNC in the options, the sounds won't play at the same time -- that is, if i try to make it play right after it started playing, it won't. Also, can't get it to loop. Help me or Die.

Playsound On VBA Excel
Hi everybody...
Do you know how to playsound (wav file) on VBA MS-Excel Macro?
For example, if value on one cell in Excel between 50 and 51, wav file will play.
Thanks before...

PlaySound Command?
What's the function to play a sound I cant find it anywhere. Sorry for the bother, can anyone just let me know? Thanks in advance.

Playsound Problem
Why doesn't this code work???

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 open_Click()
CommonDialog1.Filter = "Mp3 files (*.mp3)|*.mp3|Wave Files (*.wav)|*.wav|Midi files (*.mid)|*.mid"
CommonDialog1.DefaultExt = ".mp3"
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then
Cancel = 1
Else
play.Enabled = True
End If
soundfile$ = CommonDialog1.FileName
End Sub

Private Sub play_click()
PlaySound CommonDialog1.FileName, ByVal 0&, SND_FILENAME Or SND_ASYNC
End Sub

Private Sub Form_Load()
play.Enabled = False
End Sub

If i press play button (play_click), nothing happens but a "default beep sound"

Playsound Problem ??
I have written a VBA progam what uses Playsound and two *.wav files that are called at various times during the program. I wrote the program on the desktop using winxp and after it was running properly I copied it to my laptop. It ran for about a week on the laptop and then the wav files would not play. I transferred the program back to the desktop and it played OK. I also replaced the winmm.dll file on the laptop with the one I had on the desktop plus the two wav files. It appears that something in the laptop has changed and I have replaced all of the files that could cause a problem. I can't think of anything else that i can do at this point. Anybody have any suggestions on what could be stopping the laptop from locating the wav files which are located in the same directory as the program. I also placed the winmm.dll in the same directory which didn't help.

PlaySound Isn't Working...
I am using the PlaySound API and it isn't playing a sound. I checked the return value and it is 0 which is suppose to mean it doesnt work, but then using the GetLastError API, it says it is. Here is how I am calling the function:


Code:
...
PlaySound App.Path + "GetDot.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
...

And in a module I have the declaration and constants like so:


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

Public Const SND_ASYNC = &H1
Public Const SND_FILENAME = &H20000
...

It doesnt pop up an error or anything, I just dont hear anything come from the speakers. Any ideas what I am doing wrong?

PlaySound Problems
I know how to use this API, but Iím encountering a slight problem. I'm not sure which combination of flags to use when trying to play multiple wave files at once. By this Iím want loop some music in the background while also playing wave files according to user events (mouse down, key down etc). I donít the wave sounds generated by user events to interrupt the background music and if the user clicks multiple times I donít want the previous instance of the sound to be interrupted.

E.g. User clicks > shotgun sound is played > user clicks again before shotgun sound is finished > 1st instance of the shotgun sound is cut short and new sound is played. This usually occurs when using the snd_async flag is used.

Any ideas, is this possible with this particular api?

Can't Get My PLaySound To Work
HI


Code:
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 Command1_Click()

PlaySound LoadResData(302, "WAVE") ByVal 0&, SND_ASYNC

End Sub
Whats wrong with my code?

//Andi

PlaySound Async
Hi All:

I've done extensive searching both on these forums and on the net, and can't find an answer.

Am using a resource file to play sounds. The following code is in module1. From various places within the program I'll call to play a specific sound.

Example: PlayMySound 104

Everything works fine but the sound plays synchronously. I need to have it play asynchronously.

I thought I could just change SND_SYNC to SND_ASYNC, but when I do, then no sound plays at all.

Any thoughts?


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

Private Declare Function PlaySound Lib "WINMM.DLL" Alias "PlaySoundA" (ByRef Sound As Any, _
ByVal hLib As Long, ByVal lngflag As Long) As Long 'BOOL

Public Sub PlayMySound(k)
Dim DataArray() As Byte
DataArray = LoadResData(k, "WAVE")
Call PlaySound(DataArray(0), 0, SND_MEMORY Or SND_NODEFAULT Or SND_SYNC)
Erase DataArray
End Sub

PlaySound - How To Loop?
Ok, so I'm thick. But how on earth do I get this code to LOOP the sound so it keeps playing? I can't get it to work...

Code:
Option Explicit

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 Command1_Click()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
PlaySound "C:WINDOWSMEDIATADA.WAV", ByVal 0&, SND_FILENAME Or SND_ASYNC
End Sub

PlaySound Annoyances
I'm trying to make a wav play whilst continuing the rest of the program. I am using the Snd_Async argument, but the following code only executes after the sound has finished playing.

Any help would be appreciated,

Many Thanks

PlaySound API Call
Also, i am trying to make my autorun program play click.wav when i click on it...but it doesnt work..

this is the code i have (i'm using Visual basic .net)


VB Code:
Private Sub Label2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label2.Click       PlaySound(System.Reflection.Assembly.GetExecutingAssembly.Location & "CLICK.WAV", 0, 1) End Sub

PlaySound Quietly?
Why does PlaySound play sounds more quieltly than if you play them in Media Player.
I've got Homer Simpsom commenting on user ability in one of my programs and I want him to be heard.

Problem With Playsound ???
Hi..I'm using his basic code to playsound...but when I run the progrm get freezed...I can not close until the sound clip finishes....what I should add to this code in order to avoid this problems

-----------------
Option Explicit
'Get the function on winmm.dll

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal WavfileLocation As String, ByVal b As Long, _
ByVal c As Long) As Long

Public Sub PlayTheFile()

End Sub

Private Sub Command1_Click()
Dim Retval As Long
Retval = PlaySound("C:My DocumentsLayer-3.mp3", 0, 0)
End Sub

----------------------

Hours And Playsound
Ok i have a label displaying the time and refreshing...i was wondering..

how would i make my program play a sound using the PlaySound API call when the time reaches x o'clock (x being whatever hour it is).

PlaySound SND_SYSTEM?
Can someone please tell me declare for the new Vista only flag SND_SYSTEM that PlaySound uses?

It is reported here but I failed to see where the declaration is:
http://msdn2.microsoft.com/en-us/library/ms712879.aspx

Thanks

 

PlaySound ( Beep )...... How????
Have anice day,


Im try to give voice meesage (alarm) but I can not please I need the code and how I can user the commands to control the voice alarm ( Beep ).

Regards.

Sniper.

Playsound Problems
Hello, I read a recent post about vb6 sounds by ebk222 and used that module and now when a sound plays before an after the wave it makes a really annoying SCRATCH like sounds can anyone tell me why its doing this an possibly a fix

PlaySound Problem
hi,
my application initializes five different application and when user click button,its minimized the current application and restore next application, problem arrives when i used PlaySound to announce the name of the current application to be maximized
PlaySound("\STMCG\SOUND\Phone.wav",NULL,SND_SYNC|SND_FILENAME);
it starts switching the applicationa automatically with out user interaction(without put pressing any button) ,it execuates all cases of the Switch statement continously with out breaking

Thanks
moaz

Playsound - Playing 2 Sounds At Once
right now my line of code for playing background music is:


Code:
PlaySound App.Path & "audio
unman1.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC Or SND_LOOP
But when i attempt to play another sound that is in the game, which is done by this line:


Code:
PlaySound App.Path & "audiofire.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
the background music stops... i dont want it to stop... what am i doing wrong or not doing ?

What Is The Difference Between Playsound And Sndplaysound ?
can anyone please tell me what's the difference between playsound and sndplaysound ??

i tot also play WAV file ??

besides that, do any one know how to convert the Mp3 file to wav file ???

playsound and synplaysound only support wav file ??

What Is The Difference Between SndPlaySound And PlaySound?
Hi. What's the difference?

I only know that sndPlaySound is maintain for backward compatibility. Is there anywhere on the web that tells us the difference specifically?

Thanks!

Copyright © 2005-08 www.BigResource.com, All rights reserved