j0ker
j0ker

Reputation: 4139

Python-controllable command line audio player for Linux

I want to build use my Raspberry Pi as a media station. It should be able to play songs via commands over the network. These commands should be handled by a server written in Python. Therefor, I need a way to control audio playback via Python.

I decided to use a command line music player for linux since those should offer the most flexibility for audio file formats. Also, Python libraries like PyAudio and PyMedia don't seem to work for me.

I don't really have great expectations about the music player. It must be possible to play and pause sound files in as much codecs as possible and turn the volume up and down. Also it has to be a headless player since I am not running any desktop environment. There are a lot of players like that out there, it seems. mpg123 for example, works well for all I need.

The problem I have now is that all of these players seem to have a user interface written in ncurses and I have no idea how to access this with the Python subprocess module. So, I either need a music player which comes with Python bindings or one which can be controlled with the command line via the subprocess module. At least these are the solutions I thought about by now.

Does anyone know about a command line audio player for linux that would solve my problem? Or is there any other way?

Thanks in advance

Upvotes: 3

Views: 2364

Answers (2)

scai
scai

Reputation: 21469

mpd should be perfect for you. It is a daemon and can be controlled by various clients, ranging from GUI-less command-line clients like mpc to GUI command-line clients like ncmpc and ncmpcpp up to several full-featured desktop clients.

mpd + mpc should do the job for you as mpc can be easily controlled via the command line and is also able to provide various status information about the currently played song and other things.

It seems like there is already a python client library available for mpd - python-mpd.

Upvotes: 3

Heis Spiter
Heis Spiter

Reputation: 351

What I would recommend is that you use a media player that can be managed through D-Bus. This would solve lots of your problems.

A media player like Rythmbox can be controlled using D-Bus, but I guess it's perhaps a bit too "huge" for your Raspberry card?

Have a look there, just in case: Managing rythmbox with D-Bus

Upvotes: 1

Related Questions