tvplanit: In WavDlg play sound asynchronously and add option to turn it off.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4746 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-06-14 10:38:28 +00:00
parent 4493e26898
commit 726606df8c
4 changed files with 32 additions and 7 deletions

View File

@ -72,7 +72,7 @@ type
TVpTimeFormat = (tf24Hour, tf12Hour); TVpTimeFormat = (tf24Hour, tf12Hour);
TVpPlaySoundMode = (psmSync, psmASync); TVpPlaySoundMode = (psmSync, psmAsync, psmStop);
{ XML definitions } { XML definitions }
DOMString = WideString; DOMString = WideString;

View File

@ -892,7 +892,8 @@ begin
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
case APlaySoundMode of case APlaySoundMode of
psmSync : SndPlaySound(PChar(AWavFile), SND_SYNC); psmSync : SndPlaySound(PChar(AWavFile), SND_SYNC);
psmASync : SndPlaySound(PChar(AWavFile), SND_ASYNC); psmAsync : SndPlaySound(PChar(AWavFile), SND_ASYNC);
psmStop : SndPlaySound(nil, 0);
end; end;
{$ENDIF} {$ENDIF}
end; end;

View File

@ -102,6 +102,7 @@ object FrmSoundDialog: TFrmSoundDialog
Caption = 'OkBtn' Caption = 'OkBtn'
Default = True Default = True
ModalResult = 1 ModalResult = 1
OnClick = OkBtnClick
TabOrder = 0 TabOrder = 0
end end
object CancelBtn: TButton object CancelBtn: TButton
@ -113,6 +114,7 @@ object FrmSoundDialog: TFrmSoundDialog
Cancel = True Cancel = True
Caption = 'CancelBtn' Caption = 'CancelBtn'
ModalResult = 2 ModalResult = 2
OnClick = CancelBtnClick
TabOrder = 1 TabOrder = 1
end end
end end

View File

@ -62,12 +62,16 @@ type
CBDefault: TCheckBox; CBDefault: TCheckBox;
OkBtn: TButton; OkBtn: TButton;
CancelBtn: TButton; CancelBtn: TButton;
procedure CancelBtnClick(Sender: TObject);
procedure CBDefaultClick(Sender: TObject); procedure CBDefaultClick(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure OkBtnClick(Sender: TObject);
procedure PlayButtonClick(Sender: TObject); procedure PlayButtonClick(Sender: TObject);
private private
FOnPlaySound: TVpPlaySoundEvent; FOnPlaySound: TVpPlaySoundEvent;
function FindFileItem(AFilename: String): TListItem; function FindFileItem(AFilename: String): TListItem;
procedure PlaySound;
procedure StopSound;
public public
DingPath: string; DingPath: string;
MediaFolder: String; MediaFolder: String;
@ -88,6 +92,11 @@ uses
{$R *.dfm} {$R *.dfm}
{$ENDIF} {$ENDIF}
procedure TFrmSoundDialog.CancelBtnClick(Sender: TObject);
begin
StopSound;
end;
procedure TFrmSoundDialog.CBDefaultClick(Sender: TObject); procedure TFrmSoundDialog.CBDefaultClick(Sender: TObject);
begin begin
ShellTreeview.Visible := not CBDefault.Checked; ShellTreeview.Visible := not CBDefault.Checked;
@ -126,17 +135,24 @@ begin
Result := ''; Result := '';
end; end;
procedure TFrmSoundDialog.OkBtnClick(Sender: TObject);
begin
StopSound;
end;
procedure TFrmSoundDialog.PlayButtonClick(Sender: TObject); procedure TFrmSoundDialog.PlayButtonClick(Sender: TObject);
begin begin
DingPath := GetSelectedFileName; DingPath := GetSelectedFileName;
if Assigned(FOnPlaySound) then begin PlaySound;
PlayButton.Enabled := false;
FOnPlaySound(self, DingPath, psmSync);
PlayButton.Enabled := true;
end;
end; end;
{=====} {=====}
procedure TFrmSoundDialog.PlaySound;
begin
if Assigned(FOnPlaySound) then
FOnPlaySound(self, DingPath, psmAsync);
end;
procedure TFrmSoundDialog.Populate; procedure TFrmSoundDialog.Populate;
begin begin
TabSheet1.Caption := RSSelectASound; TabSheet1.Caption := RSSelectASound;
@ -160,5 +176,11 @@ begin
end; end;
{=====} {=====}
procedure TFrmSoundDialog.StopSound;
begin
if Assigned(FOnPlaySound) then
FOnPlaySound(self, '', psmStop);
end;
end. end.