Recent

Author Topic: Change master audio volume of my raspberry?  (Read 236 times)

Ramses

  • New Member
  • *
  • Posts: 38
Change master audio volume of my raspberry?
« on: January 21, 2021, 02:06:03 am »
As the subject said, what is the easiest way to programmatically change the master volume of my raspberry pie with lazarus? (the same master volume as the one on my task bar)

Thanks!
« Last Edit: January 21, 2021, 02:07:50 am by Ramses »

Fred vS

  • Hero Member
  • *****
  • Posts: 2083
    • StrumPract is the musicians best friend
Re: Change master audio volume of my raspberry?
« Reply #1 on: January 21, 2021, 03:31:33 pm »
As the subject said, what is the easiest way to programmatically change the master volume of my raspberry pie with lazarus? (the same master volume as the one on my task bar)

Thanks!

Hello.

The easiest way is to use a TProcess that uses this command:

Code: Pascal  [Select][+][-]
  1. $ amixer sset 'Master' 50%
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

indigo80

  • New Member
  • *
  • Posts: 37
Re: Change master audio volume of my raspberry?
« Reply #2 on: January 21, 2021, 03:43:12 pm »
As the subject said, what is the easiest way to programmatically change the master volume of my raspberry pie with lazarus? (the same master volume as the one on my task bar)

Thanks!
Code: [Select]
procedure ExecProgram(cmd:string; OutputStrings:Tstrings);
var
 P:TProcess;
begin
 P:=TProcess.Create(Nil);
 try
   P.CommandLine:=cmd;
   if OutputStrings=Nil then P.Execute  // just run, no output, not waiting
   else
   begin  // run, wait and pipe the output of the program to TStrings
     P.Options:=P.Options+[poWaitOnExit,poUsePipes];
     P.Execute;
     OutputStrings.LoadFromStream(P.Output);
   end;
 except
   // Error
 end;
 P.Free;
end;   

procedure TrackBarSoundChange(Sender: TObject);
//Change Sound Volume of the Master payback
var
 Vol:string;
begin
 if not amixer_Exists then exit;
 Vol:=IntToStr(TrackBarSound.Position)+'%';
 ExecProgram('amixer -c 0 -- sset Master playback '+Vol,Nil)
end;   

Ramses

  • New Member
  • *
  • Posts: 38
Re: Change master audio volume of my raspberry?
« Reply #3 on: January 21, 2021, 05:20:49 pm »
Alright!

Thanks a lot to both of you, it work perfectly!

 

TinyPortal © 2005-2018