Ensuring that a sound stops when process terminates

B

Bruno Köller

Robert,

had already loaded a solution, but as I don't support multiposting I'll not
send it.
 
R

Robert

Hi everyone,

I noticed that, when using PlaySound to loop a sound infinitely, it won't
stop just because the application exits. Now, normally I would consider it
my responsibility to "clean up" when quitting, but as it may be, the
application could just possibly crash.

Is there any way to ensure that the sound stops playing when the process
terminates, or is there a way to stop the sounds from another process?

Thanks!

Robert
 
R

Robert

Well, I wasn't aware of this part of netiquette.
I just wasn't sure where it would fit, and rather than writing two different
articles, I'd rather post to two groups (that way the postings are linked at
least, and won't go two seperate ways). That's what I thought.

Now it looks I can't win - If I post again, it would be multiposting. *Sigh*

Is what I'm doing right now off-topic posting or something?

Robert
 
B

Bruno Köller

His message looked crossposted to me: vb.winapi & win2000.developer.

Cross- or multiposted, asking the same question in more than one newsgroup
looks only like use of usenet as cost free self service. That's a
fundamental misunderstandement.

Why should we answer a guy who doesn't make any effort to find out the
proper newsgroup? It's our time he wastes.

But all those who find cross- or multiposting ok may feel free to answer his
question.

Just my 2c.
 
L

Larry Serflaten

Robert said:
Well, I wasn't aware of this part of netiquette.
I just wasn't sure where it would fit, and rather than writing two different
articles, I'd rather post to two groups (that way the postings are linked at
least, and won't go two seperate ways). That's what I thought.

What you did was more or less correct. Pick 2 or 3 of the most
relavent groups and include them all on the address line. To be
completely proper, you could have added just one group to the
FollowUps line so that continued discussion takes place in only
one of the groups, instead of them all.

Now it looks I can't win - If I post again, it would be multiposting. *Sigh*
Is what I'm doing right now off-topic posting or something?


Yep! <g>

As far as an answer goes, provide better error handling so your app
won't crash.

LFS
 
L

Larry Serflaten

Bruno Köller said:
Cross- or multiposted, asking the same question in more than one newsgroup
looks only like use of usenet as cost free self service. That's a
fundamental misunderstandement.

Perhaps you have your own ideas, but cost free self-service sounds like
a very good use for message forums.

Why should we answer a guy who doesn't make any effort to find out the
proper newsgroup? It's our time he wastes.

How do you know how much effort was used? If he used an API call
in VB on a Win2000 machine, how is it he is off topic? You are being
predjudice wuthout good reason. Should we make a rule that all
questions and replies have to be in perfect english? Or do you
think we should try to help those who are looking for help, even if they
are unfamiliar with the proper usage of the language or posting medium?

Just my 2c.

And that 2c has cost others looking for the same answer to go looking
elsewhere. If you understand the problem, and know the answer, then
share it. There is no reason to reply, otherwise.

LFS
 
M

MikeD

Robert said:
Hi everyone,

I noticed that, when using PlaySound to loop a sound infinitely, it won't
stop just because the application exits. Now, normally I would consider it
my responsibility to "clean up" when quitting, but as it may be, the
application could just possibly crash.

Is there any way to ensure that the sound stops playing when the process
terminates, or is there a way to stop the sounds from another process?

What exactly do you mean by "crash". Are you talking about actual crash as
in a fatal exception or similar and it's when this happens that the sound
doesn't stop? Or do you simply mean an untrapped error in your program? If
the latter, then better error handling is the answer, but even with no error
handling, the sound should stop playing. Consider the following:

Private Sub cmdError_Click()

Dim a As Long
a = 1 / 0

End Sub

Private Sub cmdStart_Click()

PlaySound "h:\winnt\media\ding.wav", 0&, SND_ASYNC Or SND_LOOP

End Sub

Private Sub cmdStop_Click()

PlaySound vbNullString, 0&, SND_ASYNC

End Sub

When run in the IDE, it's actually VB that "owns" the sound. The sound will
continue to play even after dismissal of the error message. You can either
close VB and the sound will stop, or you can rerun the program and click the
Stop button. In the compiled app, the sound will stop after dismissing the
untrapped error's message box (just as it stops in the IDE after you close
VB). I'm mentioning all of this because I kind of get the feeling that what
you noticed was that the sound still plays within the IDE and that you've
never actually "tested" this in the compiled EXE.

If you are talking about an actual crash (i.e. not a trappable runtime
error), then I still suspect that the sound should stop playing. You need
to be clearer on the exact conditions for which you noticed playback doesn't
stop. As I said, I suspect you're talking about an untrapped runtime error
and within the IDE.

Mike
 
R

Robert

Now I'm really worried about my sanity. I was absolutely sure I have tested
this in the executable...now I'm not so sure.

Thanks

Robert
 
R

Robert

OK, but if someone knows a way to stop sounds played by other processes, I'd
still be very interested.

Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top