Recent

Author Topic: TPlaySound - doesn't play sounds and causes error in debug mode.  (Read 9991 times)

CM630

  • Hero Member
  • *****
  • Posts: 1616
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TPlaySound - doesn't play sounds and causes error in debug mode.
« Reply #15 on: January 08, 2026, 08:42:07 pm »
I cannot get any sound from the VM.
The last Lazarus for my Mac is 1.2.6 (https://sourceforge.net/projects/lazarus/files/Lazarus%20Mac%20OS%20X%20powerpc/)
« Last Edit: January 08, 2026, 08:45:05 pm by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

CM630

  • Hero Member
  • *****
  • Posts: 1616
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TPlaySound - doesn't play sounds and causes error in debug mode.
« Reply #16 on: January 09, 2026, 01:54:08 pm »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: TPlaySound - doesn't play sounds and causes error in debug mode.
« Reply #17 on: January 09, 2026, 02:33:18 pm »
I don't like that you added the part about about assigning PlaySound.PlayCommand. It gives the impression that this is a fundamental step in using the component - no it isn't: as far as I understand the component (I'm not its author), exactly the same code happens during creation of the component (with more options):

Code: Pascal  [Select][+][-]
  1. constructor Tplaysound.Create(AOwner: TComponent);
  2. begin
  3.   inherited Create(AOwner);
  4.   fPlayStyle := psASync;
  5. //  fPathToSoundFile := ProgramDirectory;
  6.   {$IFDEF WINDOWS}
  7.   fDefaultPlayCommand := 'sndPlaySound';
  8.   {$ELSE}
  9.   fDefaultPlayCommand := GetNonWindowsPlayCommand; // Linux, Mac etc.
  10.   {$ENDIF}
  11.   if (fDefaultPlayCommand <> '') then FPlayCommand:=fDefaultPlayCommand;  
  12.   ...
  13. end;
  14.  
  15. function GetNonWindowsPlayCommand:String;
  16. begin
  17.   Result := '';
  18.   // Try play
  19.   if (FindDefaultExecutablePath('play') <> '') then
  20.     Result := 'play';
  21.   // Try aplay
  22.   if (result = '') then
  23.     if (FindDefaultExecutablePath('aplay') <> '') then
  24.       Result := 'aplay -q';
  25.   // Try paplay
  26.   if (Result = '') then
  27.     if (FindDefaultExecutablePath('paplay') <> '') then
  28.       Result := 'paplay';
  29.   // Try mplayer
  30.   if (Result = '') then
  31.     if (FindDefaultExecutablePath('mplayer') <> '') then
  32.       Result := 'mplayer -really-quiet';
  33.   // Try CMus
  34.   if (Result = '') then
  35.     if (FindDefaultExecutablePath('CMus') <> '') then
  36.       Result := 'CMus';
  37.   // Try pacat
  38.   if (Result = '') then
  39.     if (FindDefaultExecutablePath('pacat') <> '') then
  40.       Result := 'pacat -p';
  41.   // Try ffplay
  42.   if (Result = '') then
  43.     if (FindDefaultExecutablePath('ffplay') <> '') then
  44.       result := 'ffplay -autoexit -nodisp';
  45.   // Try mpv
  46.   if (Result = '') then
  47.     if (FindDefaultExecutablePath('mpv') <> '') then
  48.       result := 'mpv --no-video --quiet';
  49.   // Try cvlc
  50.   if (Result = '') then
  51.     if (FindDefaultExecutablePath('cvlc') <> '') then
  52.       result := 'cvlc -q --play-and-exit';
  53.   // Try canberra-gtk-play
  54.   if (Result = '') then
  55.     if (FindDefaultExecutablePath('canberra-gtk-play') <> '') then
  56.       Result := 'canberra-gtk-play -c never -f';
  57.   // Try Macintosh command?
  58.   if (Result = '') then
  59.     if (FindDefaultExecutablePath('afplay') <> '') then
  60.       Result := 'afplay';
  61. end;

Why is it required that you set the PlayCommand yourself?
« Last Edit: January 09, 2026, 03:36:14 pm by wp »

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: TPlaySound - doesn't play sounds and causes error in debug mode.
« Reply #18 on: January 09, 2026, 03:38:06 pm »
Playing with the component under mac OS (it works) and Windows I noticed that component writes the PlayCommand detected into the lfm file. I think this is a bug. Because when you compile this project under a different operating system this wrong PlayCommand is found... I think this is the reason why you started this thread...

Playcommand is normally auto-detected, and there should be normally no need for a user to enter anything here. Only when the default audio player is not detected the specific play command for your system can be specified here.

I think the issue is that, in the constructor, the component assigns the FDefaultPlayCommand to the FPlayCommand. When I comment out this line (the line before "..." in above code excerpt) the default play command is no longer written to the lfm, the project can be transferred to another operating system where the correct playcommand then can be detected anew.

Please test the new version on CCR (sourceforge) which does not contain this line any more; it should fix your initial issue without having to change the PlayCommand property of the component.
« Last Edit: January 09, 2026, 03:45:20 pm by wp »

CM630

  • Hero Member
  • *****
  • Posts: 1616
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TPlaySound - doesn't play sounds and causes error in debug mode.
« Reply #19 on: January 09, 2026, 08:08:37 pm »
...
Please test the new version on CCR (sourceforge) which does not contain this line any more; it should fix your initial issue without having to change the PlayCommand property of the component.
Thanks!
I tested it on Windows and Linux, it worked.
Now PlayCommand is empty in the object inspector.
Even on the Wiki screenshot from 2014 it is PlayCommand = sndPlaySnd (pretty odd how no one saw this issue for so long). I changed it.
I changed some other things in the Wiki, too.

« Last Edit: January 09, 2026, 08:47:39 pm by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: TPlaySound - doesn't play sounds and causes error in debug mode.
« Reply #20 on: January 09, 2026, 11:28:58 pm »
Updated OPM with the new version (0.0.10).

I changed some other things in the Wiki, too.
Good.
« Last Edit: January 09, 2026, 11:31:26 pm by wp »

 

TinyPortal © 2005-2018