You've already forked lazarus-ccr
playsoundpackage: More flexible usage of PlayCommand (empty string = builtin command). Improve demo.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5016 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -10,7 +10,7 @@ object mainform: Tmainform
|
||||
DefaultMonitor = dmPrimary
|
||||
OnCreate = FormCreate
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '1.6.0.1'
|
||||
LCLVersion = '1.7'
|
||||
object cmd_Async: TButton
|
||||
Left = 264
|
||||
Height = 25
|
||||
@ -52,20 +52,20 @@ object mainform: Tmainform
|
||||
TIObject = playsound1
|
||||
ValueFont.Color = clMaroon
|
||||
end
|
||||
object cmd_StpSound: TButton
|
||||
object cmd_StopSound: TButton
|
||||
Left = 264
|
||||
Height = 25
|
||||
Top = 112
|
||||
Width = 75
|
||||
Caption = 'Stop Sound'
|
||||
OnClick = cmd_StpSoundClick
|
||||
OnClick = cmd_StopSoundClick
|
||||
TabOrder = 4
|
||||
end
|
||||
object playsound1: Tplaysound
|
||||
About.Description.Strings = (
|
||||
'Plays WAVE sounds in Windows or Linux'
|
||||
)
|
||||
About.Title = 'About About About PlaySound'
|
||||
About.Title = 'About About About About About About PlaySound'
|
||||
About.Height = 400
|
||||
About.Width = 400
|
||||
About.Font.Color = clNavy
|
||||
@ -77,9 +77,7 @@ object mainform: Tmainform
|
||||
About.AuthorEmail = 'minesadorada@charcodelvalle.com'
|
||||
About.ComponentName = 'PlaySound'
|
||||
About.LicenseType = abLGPL
|
||||
SoundFile = '/home/gordon/development/lazarus/'
|
||||
PlayCommand = 'sndPlaySnd'
|
||||
left = 4
|
||||
top = 8
|
||||
left = 104
|
||||
top = 40
|
||||
end
|
||||
end
|
||||
|
@ -6,7 +6,7 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, RTTIGrids, Forms, Controls, Graphics, Dialogs,
|
||||
StdCtrls, Buttons, uplaysound;
|
||||
StdCtrls, Buttons, ExtCtrls, uplaysound;
|
||||
|
||||
type
|
||||
|
||||
@ -14,13 +14,13 @@ type
|
||||
|
||||
Tmainform = class(TForm)
|
||||
BitBtn1: TBitBtn;
|
||||
cmd_StpSound: TButton;
|
||||
cmd_StopSound: TButton;
|
||||
cmd_Async: TButton;
|
||||
cmd_Sync: TButton;
|
||||
playsound1: Tplaysound;
|
||||
TIPropertyGrid1: TTIPropertyGrid;
|
||||
procedure cmd_AsyncClick(Sender: TObject);
|
||||
procedure cmd_StpSoundClick(Sender: TObject);
|
||||
procedure cmd_StopSoundClick(Sender: TObject);
|
||||
procedure cmd_SyncClick(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
private
|
||||
@ -41,26 +41,35 @@ implementation
|
||||
procedure Tmainform.cmd_AsyncClick(Sender: TObject);
|
||||
// No gap between sounds. App remains responsive
|
||||
begin
|
||||
{$IFDEF WINDOWS}
|
||||
playsound1.PlayStyle:=psASync;
|
||||
playsound1.SoundFile:='doorbell.wav';
|
||||
playsound1.Execute;
|
||||
playsound1.SoundFile:='telephone.wav';
|
||||
playsound1.Execute;
|
||||
{$ELSE}
|
||||
// Sound file taken from PropertyGrid
|
||||
playsound1.Execute;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
procedure Tmainform.cmd_StpSoundClick(Sender: TObject);
|
||||
procedure Tmainform.cmd_StopSoundClick(Sender: TObject);
|
||||
begin
|
||||
playsound1.StopSound;
|
||||
end;
|
||||
|
||||
procedure Tmainform.cmd_SyncClick(Sender: TObject);
|
||||
begin
|
||||
{$IFDEF WINDOWS}
|
||||
playsound1.PlayStyle:=psSync;
|
||||
playsound1.SoundFile:='doorbell.wav';
|
||||
playsound1.Execute;
|
||||
playsound1.SoundFile:='telephone.wav';
|
||||
playsound1.Execute;
|
||||
|
||||
{$ELSE}
|
||||
// Sound file taken from PropertyGrid
|
||||
playsound1.Execute;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
procedure Tmainform.FormCreate(Sender: TObject);
|
||||
|
@ -19,10 +19,12 @@ type
|
||||
SoundPlayerSyncProcess: Tprocess;
|
||||
{$ENDIF}
|
||||
fPlayCommand:String;
|
||||
fDefaultPlayCommand: String;
|
||||
fPathToSoundFile: string;
|
||||
fPlayStyle: TPlayStyle;
|
||||
protected
|
||||
{ Protected declarations }
|
||||
function GetPlayCommand: String;
|
||||
procedure PlaySound(const szSoundFilename: string); virtual;
|
||||
public
|
||||
{ Public declarations }
|
||||
@ -100,11 +102,11 @@ constructor Tplaysound.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
fPlayStyle := psASync;
|
||||
fPathToSoundFile := ProgramDirectory;
|
||||
// fPathToSoundFile := ProgramDirectory;
|
||||
{$IFDEF WINDOWS}
|
||||
fPlayCommand:='sndPlaySnd';
|
||||
fDefaultPlayCommand := 'sndPlaySound';
|
||||
{$ELSE}
|
||||
fPlayCommand:=GetNonWindowsPlayCommand; // Linux, Mac etc.
|
||||
fDefaultPlayCommand := GetNonWindowsPlayCommand; // Linux, Mac etc.
|
||||
{$ENDIF}
|
||||
// About Dialog properties
|
||||
AboutBoxComponentName := 'PlaySound';
|
||||
@ -143,6 +145,14 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TPlaySound.GetPlayCommand: String;
|
||||
begin
|
||||
if FPlayCommand = '' then
|
||||
Result := FDefaultPlayCommand
|
||||
else
|
||||
Result := FPlayCommand;
|
||||
end;
|
||||
|
||||
procedure Tplaysound.PlaySound(const szSoundFilename: string);
|
||||
var
|
||||
{$IFDEF WINDOWS}
|
||||
@ -150,6 +160,7 @@ var
|
||||
{$ELSE}
|
||||
L: TStrings;
|
||||
i: Integer;
|
||||
playCmd: String;
|
||||
{$ENDIF}
|
||||
begin
|
||||
{$IFDEF WINDOWS}
|
||||
@ -166,16 +177,17 @@ begin
|
||||
// How to play in Linux? Use generic Linux commands
|
||||
// Use asyncprocess to play sound as SND_ASYNC
|
||||
// proceed if we managed to find a valid command
|
||||
if (fPlayCommand <> '') then
|
||||
playCmd := GetPlayCommand;
|
||||
if (playCmd <> '') then
|
||||
begin
|
||||
L := TStringList.Create;
|
||||
try
|
||||
L.Delimiter := ' ';
|
||||
L.DelimitedText := fPlayCommand;
|
||||
L.DelimitedText := playCmd;
|
||||
if fPlayStyle = psASync then
|
||||
begin
|
||||
if SoundPlayerAsyncProcess = nil then
|
||||
SoundPlayerAsyncProcess := Tasyncprocess.Create(nil);
|
||||
SoundPlayerAsyncProcess := TaSyncProcess.Create(nil);
|
||||
SoundPlayerAsyncProcess.CurrentDirectory := ExtractFileDir(szSoundFilename);
|
||||
SoundPlayerAsyncProcess.Executable := FindDefaultExecutablePath(L[0]);
|
||||
SoundPlayerAsyncProcess.Parameters.Clear;
|
||||
@ -193,7 +205,7 @@ begin
|
||||
else
|
||||
begin
|
||||
if SoundPlayerSyncProcess = nil then
|
||||
SoundPlayerSyncProcess := Tprocess.Create(nil);
|
||||
SoundPlayerSyncProcess := TProcess.Create(nil);
|
||||
SoundPlayerSyncProcess.CurrentDirectory := ExtractFileDir(szSoundFilename);
|
||||
SoundPlayerSyncProcess.Executable := FindDefaultExecutablePath(L[0]);
|
||||
SoundPlayersyncProcess.Parameters.Clear;
|
||||
|
Reference in New Issue
Block a user