Yes I did mean TMemoryStream. I'm loading the wav file from a
TFileStream, used throughout the app, into a TMemoryStream in one method
of my class, then running it from another. But the results are the same
even when I load the file directly into the MemoryStream, so that's not
the problem. Here's the basic code that works the best so far in a
long-form, test version.
I've tried different code methods, changed line orders, and used
various SoundPlay parameters, but this gets the synch between setting
the
DigitalTimer.Caption and playing the Wav file as close as I've been able
to get it, but still they're a second and a half apart! And using
pointer methods they're almost a full two seconds apart! Also, I don't
understand why the sound won't even play if I use a SND_ASYNC parameter?
VAR : SelTimerAlarmWavFileMS : TMemoryStream;
SelTimerAlarmWavFile : String;
TimerAmt : Integer;
Procedure MainF1.SetTime(Sender: TObject);
Var
SelTimerAlarmWavFileFS : TFileStream;
Size : Integer;
Begin
try
SelTimerAlarmWavFile := 'C:]Windows\Media\ringout.wav';
SelTimerAlarmWavFileFS := TFileStream.Create(SelTimerAlarmWavFile,
fmOpenRead);
SelTimerAlarmWavFileMS := TMemoryStream.Create;
SelTimerAlarmWavFileMS.copyFrom(SelTimerAlarmWavFileFS,
SelTimerAlarmWavFileFS.Size);
If SelTimerAlarmWavFileFS <> nil then
FreeAndNil(SelTimerAlarmWavFileFS);
Timer2.Enabled := True;
Except
SelTimerAlarmWavFileFS <> nil then
FreeAndNil(SelTimerAlarmWavFileFS);
ShowMessage(Error14);
End;
End;
Procedure MainF1.Timer2Timer(Sender: TObject);
Var
DigitalCount, Sec, Min, Hrs, TimerAmtInSec : Integer;
Begin
try
Inc(DigitalCt);
if Sec < 59 then
begin
Inc(Sec)
end
Else
begin
Sec := 0;
if Min < 59 then
begin
Inc(Min)
end
Else
begin
Min := 0;
Inc(Hrs);
end;
end;
DigitalTimer.Caption := IntToStr(Hrs) + ':' + IntToStr(Min) + ':' +
IntToStr(Sec);
if DigitalCt = TimerAmtInSec then
begin
PlaySound(SelTimerAlarmWavFileMS.Memory, 0, SND_MEMORY or
SND_NODEFAULT or SND_SYNC);
Timer2.Enabled := False;
DigitalCt := 0;
SelTimerCaption := TimerAmt;
If SelTimerAlarmWavFileMS <> nil then
FreeAndNil(SelTimerAlarmWavFileMS);
end;
Except
If SelTimerAlarmWavFileMS <> nil then
FreeAndNil(SelTimerAlarmWavFileMS);
ShowMessage(Error15);
End;
end;
from Robert Meek dba "Tangentals Design"
e-mail: [EMAIL PROTECTED]
Freelance Windows Programming for XP and Vista
Also proud to be a Moderator of the "Delphi-List" at elists.org
"Reality cannot be explained...only enjoyed or endured as your current
perspective allows!"
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Rob Kennedy
Sent: Saturday, June 30, 2007 2:45 AM
To: Borland's Delphi Discussion List
Subject: Re: More ion playing WAV files
Robert Meek wrote:
> I find this difficult to understand. I'm loading a Wav file
> into a TFileStream, and getting a pointer in a method run before my
> timing method is started. I then play the wav file from RAM at the
end
> of a user-set time.
What are you getting a pointer to? TFileStream doesn't hold any file
data.
Did you mean TMemoryStream?
> I tried this a couple of different ways, including the use of
> code I found on the net that others recommended,
The phrase "code I found on the net" is not one that inspires confidence
in its reliability or correctness.
--
Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi