Interrupting StockAudioPlayer1.PlayStock with new item

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

Interrupting StockAudioPlayer1.PlayStock with new item

Postby Amadeus » August 20th, 2007, 11:19 pm

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.
Amadeus
Member
Member
 
Posts: 3
Joined: August 20th, 2007, 10:10 pm

Postby Kambiz » August 21st, 2007, 6:27 pm

Set Active property to False.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby Amadeus » August 22nd, 2007, 1:01 am

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.
Amadeus
Member
Member
 
Posts: 3
Joined: August 20th, 2007, 10:10 pm

Postby Kambiz » August 22nd, 2007, 2:05 am

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;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby Amadeus » August 22nd, 2007, 2:49 am

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.
Amadeus
Member
Member
 
Posts: 3
Joined: August 20th, 2007, 10:10 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron