Recent

Author Topic: [SOLVED]playsound  (Read 4678 times)

MVD

  • New Member
  • *
  • Posts: 23
[SOLVED]playsound
« on: September 29, 2017, 11:51:55 pm »
I am working in windows 10.
I wish to play two sounds one after the other. I do it with playsound but how can I know that the first sound is finished before starting the second.
his code is working but the second wav is starting directly.
playsound1.SoundFile:=('sound\' + diertekst + 'stem.wav');
playsound1.Execute;
playsound1.SoundFile:=('sound\' + diertekst + '.wav');
playsound1.Execute;
« Last Edit: October 01, 2017, 11:36:42 am by MVD »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: playsound
« Reply #1 on: September 30, 2017, 12:26:56 am »
hello,
if you use a TPlaysound  component, set the PlayStyle property to psSync
Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

MVD

  • New Member
  • *
  • Posts: 23
Re: playsound
« Reply #2 on: September 30, 2017, 11:26:19 am »
hello,
if you use a TPlaysound  component, set the PlayStyle property to psSync
Friendly, J.P
Thanks, it helps but now I have an other question

procedure TForm1.CBExKies_DierChange(Sender: TObject);
VAR
  diertekst:string;
  positie:integer;

begin
positie := CBExKies_Dier.ItemIndex;
diertekst:= CBExKies_Dier.ItemsEx.ComboItems[positie].Caption    ;
afbeelding.Picture.LoadFromFile('image\' + diertekst + '.png');
playsound1.SoundFile:=('sound\' + diertekst + 'stem.wav');
playsound1.Execute;
playsound1.SoundFile:=('sound\' + diertekst + '.wav');
playsound1.Execute;
end;     

Why I can see the picture only after the playsound1 play the sounds?
Is it not possible to see the picture and then hear the sound?

MVD

  • New Member
  • *
  • Posts: 23
Re: playsound
« Reply #3 on: September 30, 2017, 12:11:39 pm »
This is working.

procedure TForm1.CBExKies_DierChange(Sender: TObject);
VAR

  positie:integer;

begin
positie := CBExKies_Dier.ItemIndex;
diertekst:= CBExKies_Dier.ItemsEx.ComboItems[positie].Caption    ;
afbeelding.Picture.LoadFromFile('image\' + diertekst + '.png');
Timer1.Enabled:=true;
start:=0;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
dec(start);
if start<0 then
Timer1.Enabled:=false;
playsound1.SoundFile:=('sound\' + diertekst + 'stem.wav');
  playsound1.Execute;
  playsound1.SoundFile:=('sound\' + diertekst + '.wav');
  playsound1.Execute;
end;     

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: playsound
« Reply #4 on: September 30, 2017, 12:46:40 pm »
Why I can see the picture only after the playsound1 play the sounds?
If you look at your code then you can see that there are a couple of statements following each other one by one.

The problem however is that loading a picture will load the picture from disk, store the graphics data into memory, prepare the graphics to finally send a request to the GUI to update the control that displays the picture for you. This GUI update can happen only after the update request is received and being handled, but since your code is still running it will 'block' this request.

Quote
Is it not possible to see the picture and then hear the sound?
Yes. Make a call to application.processmessages directly after loading the picture and before playing the sound. With this call you do an explicit request to handle the (pending) messages, which would include the request to update your graphics control.

No need to complicate things with using a timer, although the effect is the same: you offer your application time to handle the update message so that the GUI has time to be able to update its graphics.
« Last Edit: September 30, 2017, 01:14:44 pm by molly »

MVD

  • New Member
  • *
  • Posts: 23
[SOLVED] playsound
« Reply #5 on: September 30, 2017, 01:16:48 pm »
 everyday we are learning especially if we know so little.

Thank you for giving time to others. :)
« Last Edit: October 01, 2017, 11:34:55 am by MVD »

 

TinyPortal © 2005-2018