Page 1 of 1

controlling mpg321

Posted: Tue Mar 18, 2014 10:42 am
by sqrtmo
hi all

I am quite new in python, so I am trying to achieve a potentiometer remote control of the sound gain using mpg321 and python.
This is my try to make a player, the problem is that this way I can not control the gain on fly by variable.

Can anyone help me?
Thank's in advance.

Code: Select all

from subprocess import Popen, PIPE, STDOUT

vol = 0
vol = raw_input('set Volume ')
vol = str(vol)

p = Popen(['mpg321', '-R', 'n', '-g', vol], stdin = PIPE, stdout = PIPE, stderr = PIPE)
mpgOpen = p.communicate(input = 'LOAD 1.mp3')

Re: controlling mpg321

Posted: Thu Mar 20, 2014 11:30 pm
by paddyg
I did some stuff with mpg321 here
https://github.com/pi3d/pi3d_demos/blob ... Jukebox.py try using

Code: Select all

p.stdin.write(b'GAIN 43\n')
this seems to work ok for me

Re: controlling mpg321

Posted: Tue Mar 25, 2014 11:52 am
by sqrtmo
OK, I made it with pygame instead of mpg321. It is quite simple, but is isn't work good with mp3 files, I don't know why is plays mp3's on higher speed..

Re: controlling mpg321

Posted: Tue Mar 25, 2014 12:34 pm
by elParaguayo
I think mp3 is not officially supported in pygame. See this: http://pygame.org/docs/ref/music.html
Be aware that MP3 support is limited. On some systems an unsupported format can crash the program, e.g. Debian Linux. Consider using OGG instead.

Re: controlling mpg321

Posted: Fri Apr 04, 2014 7:57 am
by sqrtmo
Yes I have read this. OK with no alternative finally I have made it with pygame. It works prefect, but I think eats more CPU then playing mp3 with mpg321. So this is my solution for now.

Thanks a lot for replays!