sqrtmo
Posts: 3
Joined: Tue Mar 18, 2014 10:13 am

controlling mpg321

Tue Mar 18, 2014 10:42 am

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')

User avatar
paddyg
Posts: 2555
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: controlling mpg321

Thu Mar 20, 2014 11:30 pm

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
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

sqrtmo
Posts: 3
Joined: Tue Mar 18, 2014 10:13 am

Re: controlling mpg321

Tue Mar 25, 2014 11:52 am

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..

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: controlling mpg321

Tue Mar 25, 2014 12:34 pm

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.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

sqrtmo
Posts: 3
Joined: Tue Mar 18, 2014 10:13 am

Re: controlling mpg321

Fri Apr 04, 2014 7:57 am

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!

Return to “Python”