Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

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
0
4099aol
Asked:
4099aol
  • 19
  • 16
1 Solution
 
q2guoCommented:
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
 
4099aolAuthor Commented:
sounds better, but how can I get the pause out of it??
0
 
q2guoCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
4099aolAuthor Commented:
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
 
q2guoCommented:
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
 
4099aolAuthor Commented:
ohh ok, so it will play the sound over and over and over again until the sleep is over??

thanks
0
 
q2guoCommented:
Exactly!
Are you still getting the pause?
0
 
4099aolAuthor Commented:
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
 
q2guoCommented:
try this instead

PlaySound ("reg.wav", 0, SND_LOOP+SND_ASYNC);
Sleep(2500)
PlaySound (NULL, 0, SND_LOOP+SND_ASYNC);
0
 
4099aolAuthor Commented:
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
 
q2guoCommented:
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
 
4099aolAuthor Commented:
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
 
4099aolAuthor Commented:
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
 
q2guoCommented:
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
 
4099aolAuthor Commented:
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
 
4099aolAuthor Commented:
I am trying it now...
0
 
4099aolAuthor Commented:
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
 
4099aolAuthor Commented:
The second set codes comes up with the same error message...
0
 
q2guoCommented:
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
 
4099aolAuthor Commented:
same error message...
0
 
q2guoCommented:
what if you put in only these three lines

FILE *regcd;
regcd = fopen("regcd.dat",  "w")
fclose(regcd);
0
 
q2guoCommented:
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
 
4099aolAuthor Commented:
FILE *regcd;
regcd = fopen("regcd.dat", "w")
fclose(regcd);

works, but how does it know which editbox to look at??
0
 
q2guoCommented:
So, we know it's
the line
fprintf(regcd, "%s", (Edit1->Text).c_str());
that is causing the error
0
 
4099aolAuthor Commented:
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
 
q2guoCommented:
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
 
4099aolAuthor Commented:
nope same error message....
0
 
q2guoCommented:
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
 
q2guoCommented:
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
 
4099aolAuthor Commented:
[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
 
4099aolAuthor Commented:
i will check it out now!
0
 
q2guoCommented:
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
 
4099aolAuthor Commented:
same error message...
0
 
q2guoCommented:
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
 
4099aolAuthor Commented:
thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 19
  • 16
Tackle projects and never again get stuck behind a technical roadblock.
Join Now