Solved

Play a wav file 5 times???

Posted on 1998-02-15
35
323 Views
Last Modified: 2010-04-10
I currently use PlaySound ("reg.wav",  0, SND_ASYNC); to play a wav file, but it only plays it once.  How can I get it to play the sound 5 times??  If I do this...

PlaySound ("reg.wav",  0, SND_ASYNC);
PlaySound ("reg.wav",  0, SND_ASYNC);
PlaySound ("reg.wav",  0, SND_ASYNC);
PlaySound ("reg.wav",  0, SND_ASYNC);
PlaySound ("reg.wav",  0, SND_ASYNC);

It plays them all at once, and sounds very bad.

thanks
0
Comment
Question by:4099aol
  • 19
  • 16
35 Comments
 
LVL 3

Accepted Solution

by:
q2guo earned 20 total points
ID: 1182177
Try this 4099AOL

use the SND_SYNC flag rather than the SND_ASYNC

PlaySound ("reg.wav", 0, SND_SYNC);
PlaySound ("reg.wav", 0, SND_SYNC);
PlaySound ("reg.wav", 0, SND_SYNC);
PlaySound ("reg.wav", 0, SND_SYNC);
PlaySound ("reg.wav", 0, SND_SYNC);
0
 

Author Comment

by:4099aol
ID: 1182178
sounds better, but how can I get the pause out of it??
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182179
PlaySound ("reg.wav", 0, SND_LOOP+SND_ASYNC);  

// add some kind of delay here
// it can either be a time delay for
// 5*the length of the reg.wav
// ,it can be opening of dialog box
// or it can show a opening screen of a program
// For example Call funcation 'Sleep(1000)'; to play the wave // // file for one second

PlaySound (NULL, 0, 0);

The first Playsound statement opens the wav file and start playing, loops if nessesary. The line PlaySound(NULL, 0, 0)  stops it
0
 

Author Comment

by:4099aol
ID: 1182180
So i do this??

PlaySound ("reg.wav", 0, SND_LOOP+SND_ASYNC);
Sleep(1000)
PlaySound (NULL, 0, 0);

But wouldn't that make it pause even more??  I want it to not pause at all..
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182181
No, this would not pause it at all.
You are looking at the difference between SND_ASYNC
and SND_SYNC

Sleep(1000);

This will only let you play the wav file for one second
if you want to play for 3 seconds, you would write

Sleep(3000);

0
 

Author Comment

by:4099aol
ID: 1182182
ohh ok, so it will play the sound over and over and over again until the sleep is over??

thanks
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182183
Exactly!
Are you still getting the pause?
0
 

Author Comment

by:4099aol
ID: 1182184
thanks I set it for 2500 (2.5 seconds) it works just fine.   but now, after the sleep it locks up when it tries to create rgnum.dat, why??
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182185
try this instead

PlaySound ("reg.wav", 0, SND_LOOP+SND_ASYNC);
Sleep(2500)
PlaySound (NULL, 0, SND_LOOP+SND_ASYNC);
0
 

Author Comment

by:4099aol
ID: 1182186
ok that is not what is messing up, I commented out the whole sound thing (with //) and it still locked up.  It is saying it can't create regnum.dat, could that it already exists??
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182187
comment out the line below
and see if you are still getting stuck.
or getting the out memory message.

MyStringList->SaveToFile("regnum.dat");

also, where is this regnum.dat located exactly.
0
 

Author Comment

by:4099aol
ID: 1182188
sorry I told you the wrong information.. it is locking up when it trys to add to user.dat. here is the ending of the shareware registration code validation ..

 // This part ONLY runs if the reg code is correct
 if (ValidationOk)
    {
     //Play reg sound
     PlaySound ("reg.wav", 0, SND_LOOP+SND_ASYNC);
     Sleep(2500);
     PlaySound (NULL, 0, SND_LOOP+SND_ASYNC);

     //Show a thanks for registering message
     Application->MessageBox("Thank you for registering!!", "Validation", MB_OK);

     // Put contents of Edit1 into regcd.dat
     TStringList *MyStringList = new TStringList;
     MyStringList->Add(Edit1->Text);
     MyStringList->SaveToFile("regcd.dat");

     // Put contents of Edit2 into user.dat
     TStringList *MyStringList1 = new TStringList;
     MyStringList1->Add(Edit2->Text);
     MyStringList1->SaveToFile("user.dat");
    }

delete[] Buffer;
}


what is wrong with it?????????

I think it is because user.dat already exists.

0
 

Author Comment

by:4099aol
ID: 1182189
Sorry it was locking on regcd.dat.

Also I tried to have regcd.dat and user.dat before writting to it but it still locked up.  Also for your reff I used int result = remove("user.dat"); to delete the files..
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182190
Try this

FILE *regcd;
FILE *user;

// Put contents of Edit1 into regcd.dat
regcd = fopen("regcd.dat", "w")
fprintf(regcd, "%s", Edit1->Text);
fclose(regcd);

// Put contents of Edit2 into user.dat
user = fopen("regcd.dat", "a")
fprintf(user, "%s", Edit2->Text);
fclose(user);

-------------------------------------------------
if above doesn't work try this


FILE *regcd;
FILE *user;

// Put contents of Edit1 into regcd.dat
regcd = fopen("regcd.dat", "w")
fprintf(regcd, "%s", (Edit1->Text).c_str());
fclose(regcd);

// Put contents of Edit2 into user.dat
regcd = fopen("regcd.dat", "a")
fprintf(user, "%s", (Edit2->Text).c_str());
fclose(user);

0
 

Author Comment

by:4099aol
ID: 1182191
I commented out the following codes and it worked fine...
// Put contents of Edit1 into regcd.dat
 TStringList *MyStringList = new TStringList;
 MyStringList->Add(Edit1->Text);
 MyStringList->SaveToFile("regcd.dat");

//Put contents of Edit2 into user.dat
 TStringList *MyStringList1 = new TStringList;
 MyStringList1->Add(Edit2->Text);
 MyStringList1->SaveToFile("user.dat");

So the error is in that code, could you please tell me what is wrong with it??
0
 

Author Comment

by:4099aol
ID: 1182192
I am trying it now...
0
 

Author Comment

by:4099aol
ID: 1182193
I used the first set of codes.  THis popup message came up..

Project webmaste1.exe raised exception class EAcessViolation with message 'Acces violation at address 00444E60'. Read of address 007BD23C.

what ever all that means..
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:4099aol
ID: 1182194
The second set codes comes up with the same error message...
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182195
FILE *regcd;
FILE *user;

// Put contents of Edit1 into regcd.dat
regcd = fopen("regcd.dat", "w")
fprintf(regcd, "%s", (Edit1->Text).c_str());
fclose(regcd);

// Put contents of Edit2 into user.dat
user = fopen("user.dat", "a")
fprintf(user, "%s", (Edit2->Text).c_str());
fclose(user);
0
 

Author Comment

by:4099aol
ID: 1182196
same error message...
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182197
what if you put in only these three lines

FILE *regcd;
regcd = fopen("regcd.dat",  "w")
fclose(regcd);
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182198
Also try this

// Put contents of Edit1 into regcd.dat
AnsiString S(Edit1->Text)
TStringList *MyStringList = new TStringList;
MyStringList->Add(S);
MyStringList->SaveToFile("regcd.dat");

// Put contents of Edit2 into user.dat
AnsiString S2(Edit2->Text)
TStringList *MyStringList1 = new TStringList;
MyStringList1->Add(S2);
MyStringList1->SaveToFile("user.dat");
0
 

Author Comment

by:4099aol
ID: 1182199
FILE *regcd;
regcd = fopen("regcd.dat", "w")
fclose(regcd);

works, but how does it know which editbox to look at??
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182200
So, we know it's
the line
fprintf(regcd, "%s", (Edit1->Text).c_str());
that is causing the error
0
 

Author Comment

by:4099aol
ID: 1182201
guess so, but the three lines of codes work.  The only problem with it is that I do not know how to get it to work with both Edit1 and Edit2
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182202
Try this again

FILE *regcd;
FILE *user;

// Put contents of Edit1 into regcd.dat
regcd = fopen("regcd.dat", "w");
AnsiString S(Edit1->Text);
fprintf(regcd, "%s", S.c_str());
fclose(regcd);

// Put contents of Edit2 into user.dat
user = fopen("user.dat", "a");
AnsiString S2(Edit2->Text);
fprintf(user, "%s", S2.c_str());
fclose(user);

0
 

Author Comment

by:4099aol
ID: 1182203
nope same error message....
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182204
Hi 4099aol,
I think I find the problem

                       FILE *regcd;
                       FILE *user;

                       // Put contents of Edit1 into regcd.dat
                       regcd = fopen("regcd.dat", "w");
                       AnsiString S(Edit1->Text);
                       fprintf(regcd, "%s", S->c_str());
                       fclose(regcd);

                       // Put contents of Edit2 into user.dat
                       user = fopen("user.dat", "a");
                       AnsiString S2(Edit2->Text);
                       fprintf(user, "%s", S2->c_str());
                       fclose(user);
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182205
hi 4099aol
Just want to let you know, you can obtain the complete
documentation on Borland Builder at
http://www.borland.com/techpubs/bcppbuilder/
The documentation is approximately 30MB.
0
 

Author Comment

by:4099aol
ID: 1182206
[C++ Error] Options.cpp(351): Pointer to structure required on left side of -> or ->*.

[C++ Error] Options.cpp(357): Pointer to structure required on left side of -> or ->*.

[C++ Warning] Options.cpp(362): 'S2' is assigned a value that is never used.
0
 

Author Comment

by:4099aol
ID: 1182207
i will check it out now!
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182208
Try this

FILE *regcd;
FILE *user;

// Put contents of Edit1 into regcd.dat
regcd = fopen("regcd.dat", "w");
fprintf(regcd, "%s", (Edit2->Text)->c_str());
fclose(regcd);

// Put contents of Edit2 into user.dat
user = fopen("user.dat", "a");
fprintf(user, "%s", (Edit2->Text)->c_str());
fclose(user);
0
 

Author Comment

by:4099aol
ID: 1182209
same error message...
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182210
4099aol, it's time to finish off this question.

#include <vcl\sysutils.hpp>

int regcd;
int user;

AnsiString f1name("regcd.dat");
// Put contents of Edit1 into regcd.dat
regcd = FileOpen(f1name, fmOpenWrite);

FileWrite(regcd, (char*)((Edit1->Text).c_str()), sizeof((Edit1->Text).c_str()));
FileClose(regcd);

AnsiString f2name("user.dat");
// Put contents of Edit2 into user.dat
user = FileOpen(f2name, fmOpenWrite);
FileWrite(user, (char*)((Edit2->Text).c_str()),
sizeof((Edit2->Text).c_str()));
FileClose(user);
0
 

Author Comment

by:4099aol
ID: 1182211
thanks.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now