Link to home
Start Free TrialLog in
Avatar of 4099aol
4099aol

asked on

Play a wav file 5 times???

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
ASKER CERTIFIED SOLUTION
Avatar of q2guo
q2guo

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
Avatar of 4099aol
4099aol

ASKER

sounds better, but how can I get the pause out of it??
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
Avatar of 4099aol

ASKER

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..
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);

Avatar of 4099aol

ASKER

ohh ok, so it will play the sound over and over and over again until the sleep is over??

thanks
Exactly!
Are you still getting the pause?
Avatar of 4099aol

ASKER

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??
try this instead

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

ASKER

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??
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.
Avatar of 4099aol

ASKER

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.

Avatar of 4099aol

ASKER

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..
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);

Avatar of 4099aol

ASKER

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??
Avatar of 4099aol

ASKER

I am trying it now...
Avatar of 4099aol

ASKER

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..
Avatar of 4099aol

ASKER

The second set codes comes up with the same error message...
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);
Avatar of 4099aol

ASKER

same error message...
what if you put in only these three lines

FILE *regcd;
regcd = fopen("regcd.dat",  "w")
fclose(regcd);
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");
Avatar of 4099aol

ASKER

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

works, but how does it know which editbox to look at??
So, we know it's
the line
fprintf(regcd, "%s", (Edit1->Text).c_str());
that is causing the error
Avatar of 4099aol

ASKER

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
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);

Avatar of 4099aol

ASKER

nope same error message....
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);
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.
Avatar of 4099aol

ASKER

[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.
Avatar of 4099aol

ASKER

i will check it out now!
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);
Avatar of 4099aol

ASKER

same error message...
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);
Avatar of 4099aol

ASKER

thanks.