Page 1 of 1

Interrupting StockAudioPlayer1.PlayStock with new item

PostPosted: August 20th, 2007, 11:19 pm
by Amadeus
How can I interrupt playing a file, before it has finished, without getting a "Device is already[spelling mistake here] open" error, allowing further sounds to be played in rapid succession.

A Stop method would do the trick I imagine, but is not available.

PostPosted: August 21st, 2007, 6:27 pm
by Kambiz
Set Active property to False.

PostPosted: August 22nd, 2007, 1:01 am
by Amadeus
This was the first thing I tried but setting the Active state to false alone does not seem to close the instance of the Player.

Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
  StockAudioPlayer1.Active := false;
  StockAudioPlayer1.PlayStock(0);
end;


Clicking the button before the file is played still creates an error.

PostPosted: August 22nd, 2007, 2:05 am
by Kambiz
When Async property is True, you may need to use WaitForStop method or Sleep API to wait until callback thread stops.

Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
  StockAudioPlayer1.Active := false;

  StockAudioPlayer1.WaitForStop;
  // OR
  Sleep(10);

  StockAudioPlayer1.PlayStock(0);
end;

PostPosted: August 22nd, 2007, 2:49 am
by Amadeus
That does it, the explanation is under the class methods and I didn't look beyond the component properties definitions. My mistake.

Thanks for that and thanks for creating a substitute to the TabcWaveList.