Recent

Author Topic: Play MP3/WAV files in freepascal command line on RPI 2  (Read 16462 times)

pascalbythree

  • Jr. Member
  • **
  • Posts: 71
Play MP3/WAV files in freepascal command line on RPI 2
« on: July 02, 2016, 10:35:36 am »
Does anybody have simple example code?

Thaddy

  • Hero Member
  • *****
  • Posts: 10795
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #1 on: July 02, 2016, 11:01:00 am »
 want anything more complex than TProcess that calls omxplayer? ;)

Fred vS

  • Hero Member
  • *****
  • Posts: 2283
    • StrumPract is the musicians best friend
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #2 on: July 02, 2016, 11:20:02 am »
Hello.

uos does it. (https://github.com/fredvs/uos)

Take a look at /uos/examples/consoleplay.lpi.

The libraries for RPI are in /uos/examples/lib/Linux/arm_raspberrypi/.

Fre;D
« Last Edit: July 02, 2016, 11:57:20 am by Fred vS »
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

pascalbythree

  • Jr. Member
  • **
  • Posts: 71
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #3 on: July 02, 2016, 06:09:39 pm »
Thanks, But then only for the Raspberry PI 2 ? Anyone Seperate command line Code?
« Last Edit: July 02, 2016, 06:11:15 pm by pascalbythree »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8352
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #4 on: July 02, 2016, 07:24:06 pm »
Thanks, But then only for the Raspberry PI 2 ? Anyone Seperate command line Code?
Add dependency for ffplay, then use TProcess to tell it to play the files. You get bonus of a lot of audio formats out of the box.

Fred vS

  • Hero Member
  • *****
  • Posts: 2283
    • StrumPract is the musicians best friend
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #5 on: July 02, 2016, 08:57:52 pm »
Quote
Add dependency for ffplay, then use TProcess to tell it to play the files.

Code: Pascal  [Select][+][-]
  1. procedure playsound ;
  2. var
  3.  AProcess : TProcess;
  4. begin
  5.   AProcess := TProcess.Create(nil);
  6.   AProcess.FreeOnRelease;
  7.   AProcess.Executable :=  '/path/of/sound_player' ; // path of sound-player (ffplay or omxplayer or other player)
  8.   AProcess.Parameters.Add('/path/of/sound_file.mp3') ; // path of sound-to-play
  9.   AProcess.Execute;
  10. end;

Fre;D
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

pascalbythree

  • Jr. Member
  • **
  • Posts: 71
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #6 on: July 04, 2016, 10:49:56 am »
Anybody got more RPI example code? For FPC 3.0 to edit with nano on the command line? --> No lazarus
« Last Edit: July 04, 2016, 11:20:33 am by pascalbythree »

Fred vS

  • Hero Member
  • *****
  • Posts: 2283
    • StrumPract is the musicians best friend
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #7 on: July 04, 2016, 05:30:02 pm »
Anybody got more RPI example code? For FPC 3.0 to edit with nano on the command line? --> No lazarus

1) Run nano and paste this (with right path, of course):

Code: Pascal  [Select][+][-]
  1. program playconsole;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.    SysUtils, Classes, Process ;
  7.  
  8. procedure playsound ;
  9. var
  10.  AProcess : TProcess;
  11. begin
  12.   AProcess := TProcess.Create(nil);
  13.   AProcess.FreeOnRelease;
  14.   AProcess.Executable :=  '/path/of/sound_player' ; // path of sound-player (ffplay or omxplayer or other player)
  15.   AProcess.Parameters.Add('/path/of/sound_file.mp3') ; // path of sound-to-play
  16.   AProcess.Execute;
  17. end;
  18.  
  19. begin
  20.   playsound;
  21. end.

2) Save it as playconsole.pas

3) In console, compile it with: fpc /path/of/playconsole.pas

4) in console, run it with: /path/of/playconsole

Fre;D
« Last Edit: July 04, 2016, 05:33:02 pm by Fred vS »
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

pascalbythree

  • Jr. Member
  • **
  • Posts: 71
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #8 on: July 04, 2016, 06:48:20 pm »
Yes. I rather use procedures/functions then  a seperate Process.

To play a very small mp3 on the file system.

Anybody got more examples? Still dit find something to pick to continue with it.

to compile with for example
sudo fpc ./playsound.pas
« Last Edit: July 04, 2016, 06:52:44 pm by pascalbythree »

pascalbythree

  • Jr. Member
  • **
  • Posts: 71
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #9 on: July 10, 2016, 04:22:50 pm »
Do not get it to run on my Raspberry II

Anyone got more examples?

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 986
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #10 on: July 10, 2016, 06:15:12 pm »
hello,
success on my Raspberry pi 2 B with fpc 2.6.4 and this code :
Code: Pascal  [Select][+][-]
  1. program playconsole;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.    SysUtils, Classes, Process ;
  7.  
  8. procedure playsound ;
  9. var
  10.  AProcess : TProcess;
  11. begin
  12.   AProcess := TProcess.Create(nil);
  13.   AProcess.FreeOnRelease;
  14.   AProcess.Executable :=  '/usr/bin/omxplayer' ; // path of sound-player
  15.   AProcess.Parameters.Add('-o');
  16.   Aprocess.Parameters.Add('local') ; // local = headphone  hdmi = hdmi
  17.   AProcess.Parameters.Add('/home/pi/example.mp3') ; // path of sound-to-play
  18.   AProcess.Execute;
  19. end;
  20.  
  21. begin
  22.   playsound;
  23. end.
  24.  

Friendly, J.P
« Last Edit: July 10, 2016, 06:39:09 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

pascalbythree

  • Jr. Member
  • **
  • Posts: 71
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #11 on: July 11, 2016, 08:42:31 pm »
Still buggy. Can not get rid of hanging processes yet.
Does anybody know where to download 'FFPlay4Laz_Console.exe'
« Last Edit: July 11, 2016, 08:57:41 pm by pascalbythree »

metis

  • Full Member
  • ***
  • Posts: 222
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #12 on: July 15, 2016, 03:07:17 pm »
@pascalbythree

Quote
Does anybody know where to download 'FFPlay4Laz_Console.exe'
Me, the Author, see my Post from July 08, 2016:
http://forum.lazarus.freepascal.org/index.php/topic,26666.msg215455.html#msg215455

Note:
The current Version of 'FFPlay4Laz-ConsoleVersion ' is Windows-only, and AV-only, means
Audio-only-Files are not rendered yet (but it's projected to do).           

-> To get FFPlay "all-in-one", You might have a Look at this:
http://forum.lazarus.freepascal.org/index.php/topic,33105.0.html
Still very preliminary, but maybe, one Day, it's another Option.
« Last Edit: July 15, 2016, 07:24:06 pm by metis »
Life could be so easy, if there weren't those f*** Details.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2619
    • havefunsoft.com
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #13 on: July 15, 2016, 03:10:57 pm »
How about trying openal example (wavopenal.pas) ?
from trunk

Fred vS

  • Hero Member
  • *****
  • Posts: 2283
    • StrumPract is the musicians best friend
Re: Play MP3/WAV files in freepascal command line on RPI 2
« Reply #14 on: July 18, 2016, 02:52:17 pm »
How about trying openal example (wavopenal.pas) ?
from trunk

Huh, I have try with some wav flles but get always :
Quote
"/home/fred/Téléchargements/waveopenal/test.wav" is not a core dump: File format not recognized

For example the test.wav is a common stereo 16 bit wav.

What kind of *.wav can be recognized by openal ?

And is openal.so library needed for only decoding a wav  file (no pure code only) ?

Thanks.

Fre;D
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

 

TinyPortal © 2005-2018