![]() |
sndPlaySound... und wenn fertig dann...
Hallo erst mal.
1. in Public hab ich
Code:
2. OnFormCreate
stop : boolean
Delphi-Quellcode:
3. einen button :
stop:=true;
Delphi-Quellcode:
4. den timer1 (interval=1)if stop=true then begin if sndPlaySound('C:\1.wav', snd_Async or snd_NoDefault) then begin button1.caption:='STOP'; timer1.enabled:=true; end; end else begin stop:=true; sndPlaySound(nil, snd_sync or snd_NoDefault); button1.caption:='PLAY' end;
Delphi-Quellcode:
das ganze klappt auch wunderbar so (wenn ich auf button1 klicke spielt er was und wenn ich noch mal klick dann nicht)
if button1.Caption='STOP' then stop:=false;
timer1.enabled:=false; doch jetzt würd ich gerne das ganze noch so haben dass wenn er die wave komplett gespielt hat, er dass ...
Delphi-Quellcode:
...macht.
button1.caption:='PLAY';
stop:=true; rafft den code jemand? |
Re: sndPlaySound... und wenn fertig dann...
Delphi-Quellcode:
Vielleicht hilft dir das ja ein wenig weiter!
procedure TForm1.Button1Click(Sender:TObject);
begin if Button1.Caption = 'PLAY' then begin Application.ProcessMessages; Button1.Caption:='STOP'; sndPlaySound('C:\1.wav', snd_Async or snd_NoDefault); Application.ProcessMessages; Button1Click(Button1); end else begin Button1.Caption:='PLAY' sndPlaySound(nil, snd_sync or snd_NoDefault); end; end; |
Re: sndPlaySound... und wenn fertig dann...
Delphi-Quellcode:
Oder vielleicht auch das?!?
procedure TForm1.Button1Click(Sender:TObject);
begin if Button1.Caption = 'PLAY' then begin Button1.Caption:='STOP'; Timer1.Enabled:=true; sndPlaySound('C:\1.wav', snd_Async or snd_NoDefault); end else begin Button1.Caption:='PLAY'; Timer1.Enabled:=false; sndPlaySound(nil, snd_sync or snd_NoDefault); end; end; procedure TForm1.Timer1Timer(Sender:TObject); begin sndPlaySound('C:\1.wav', snd_Async or snd_NoDefault) end; |
Re: sndPlaySound... und wenn fertig dann...
Ähm... Nein das hiflt mir nicht
|
Re: sndPlaySound... und wenn fertig dann...
Also ich würdes nicht async sondern sync verwenden. Das ganze dann in nen thread packen. Und dann beim beenden des threads die variable setzen. Kannst das natürlich auch ohne thread machen aber dann hängt die anwendung in der zeit
|
Re: sndPlaySound... und wenn fertig dann...
Ahh so klappts
Delphi-Quellcode:
weiss zwar nich warum ich am ende von PlaySound eine 0 machen musste aber es funktioniert.
if Button1.Caption = 'PLAY' then
begin Button1.Caption:='STOP'; Application.ProcessMessages; PlaySound('C:\1.wav', snd_Async or snd_NoDefault, 0); Application.ProcessMessages; button1.Caption:='PLAY' end else begin Button1.Caption:='PLAY' ; sndPlaySound(nil, snd_sync or snd_NoDefault); end; DANKE :thuimb: |
Re: sndPlaySound... und wenn fertig dann...
Ähh was ist ein "thread"
|
Re: sndPlaySound... und wenn fertig dann...
ohh.. es klappt doch nicht du hast recht ,SirThornberry, die anwendug hängt :wall:
kannst du mir das mit dem Thread mal für hauptschüler erklären ( nich das ich einer bin!!) |
Re: sndPlaySound... und wenn fertig dann...
hier bissl source der dein problem lösen sollte
Delphi-Quellcode:
TSoundThread = class(TThread)
protected procedure Execute; override; end; TForm1 = class(TForm) [...] private procedure fThreadvorbei(Sender: TObject); [...] end; [...] procedure TSoundThread.Execute; begin sndPlaySound('c:\windows\media\ringout.wav', snd_sync or snd_NoDefault) end; procedure TForm1.fThreadvorbei(Sender: TObject); begin stop:=true; end; procedure TForm1.Button1Click(Sender: TObject); var Lthread: TSoundThread; begin Lthread := TSoundThread.Create(False); LThread.OnTerminate := fThreadvorbei; LThread.Resume; stop := false; end; |
Re: sndPlaySound... und wenn fertig dann...
Ja gut soweit, doch wie kann man das jetzt so machen das wenn man mochmal
auf den button drück der playsound wieder aufhört :gruebel: (sndPlaySound(nil, snd_sync or snd_NoDefault) ) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:36 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz