Forum > Linux
Play a sound.(Resolved)
(1/1)
KesterKick:
Hi,
I guess this has been covered before but I am struggling to interpret what I have found on line. I set up a countdown timer on my Windows 7 system using Lazarus and would like to do the same on my MX-Linux 23 system.
I've used similar components and coding except for that relating to the sound file I wish to play when the countdown finishes. I am using Lazarus version 2.2.4 so any help would be greatly appreciated. I have a prepared .wav file but need help regarding how to get and install the sound component into Lazarus, as I believe it doesn't have one by default. When this is achieved I'd also like help regarding the coding to play the wav file when counting completes and to stop the sound with a TButton click.
Please bear in mind that I am well past my sell by date at 82 so may need things spelled out gently and clearly.
Thanks and good wishes to all members, cheers.
MarkMLl:
This is a big problem. There was a long thread about it a year or so ago ** , and the conclusions were:
* Particularly under Linux, different PCs, different distreaux, different desktop environments within the same distro, different versions of the same desktop environment on... (you get the idea) all behaved differently.
* Even if members of the community could find an adequate solution, the FPC developers would be extremely unlikely to contemplate accessing it via something like Beep().
From memory, I ended up with four possibilities.
* If you are on a non-graphical console, Write(#$07) might work.
* If you are using a desktop environment based on X11 (i.e. as distinct from Wayland), you might be able to use an X11 extension to make terminal beep noises.
* If you have ALSA etc. installed, you might be able to use ALSA to beep based on a PCM sequence.
* Ditto you might be able to use ALSA to emit a MIDI sequence.
Plus there's also possibilities based on various media players. I've never explored these since the amount of overhead appeared counterproductive when the objective was to start making a noise if something wasn't behaving as expected, i.e. a watchdog timer had expired etc.
You might possibly find something useful at https://github.com/MarkMLl/asound which includes interface libraries which should work with either static or dynamic linkage. I've also got a revised version here with much more of the MIDI API coded, but at present lack the time to give it a final polish before posting.
MarkMLl
** https://forum.lazarus.freepascal.org/index.php/topic,49502.msg358923.html
KesterKick:
Hi Mark,
Thanks for your extensive reply. However, digging around in my old backup files I found a copy of a timer program I created in Lazarus on Linux Mint and I remembered that that did play a sound. I looked at the code and uses list and was able to adapt that in my Lazarus timer in MX-Linux and it worked. The answer in my case was to add 'Process' to the uses and the following function:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function PlaySoundLnx(fileName: String): Boolean;const playerCmd = 'paplay'; // pulseaudio clientvar AProcess: TProcess;begin AProcess := TProcess.Create(nil); with Aprocess do begin CommandLine := FindDefaultExecutablePath(playerCmd) + ' ' + filename; //Options := Options + [poWaitOnExit]; try try Execute; except on E: Exception do ShowMessage(E.ClassName + ' error raised, with message : ' + E.Message); end; finally Free; end; end;end; and add the following to the timer start procedure:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---begin Panel7.color := clred; Panel7.caption := 'Alarm'; PlaySoundLnx('WinExc.wav') end; This provides a visual alert along with the sound.
Cheers and best wishes.
Navigation
[0] Message Index