JF002
Posts: 94
Joined: Sat Feb 04, 2012 8:49 am
Contact: Website

Play sound (mp3, streams,...) using Python

Tue Aug 28, 2012 8:42 pm

Hi!

For my project, I want to be able to play music files (MP3 stored locally or on the network, web streams,...) using Python3 (and PySide/QT4).

I found several possibilities :
* Phonon (from QT)
* Pygame
* gstreamer
* OmxPlayer
...

And I was wondering which was the best solution to play sound file and have some feedback on the playing (position in the file, total duration,...). For now, my goal is to implement a music player.

From what I understood, OmxPlayer was developped specifically for the Rpi and uses hardware for decoding. It could be the best for performances.
But... Does it have some kind of API I could use from Python?

I tried Phonon with no success for now...

Do you have some advices for me?

Thanks!
My web site : https://codingfield.com

KenT
Posts: 758
Joined: Tue Jan 24, 2012 9:30 am
Location: Hertfordshire, UK
Contact: Website

Re: Play sound (mp3, streams,...) using Python

Tue Aug 28, 2012 8:50 pm

Try this. Its Python 2.7 and Tkinter interface to omxplayer

https://github.com/KenT2/tboplayer

If you want a Python interface to omxplayer try https://github.com/jbaiter/pyomxplayer or look at my other github repo
Pi Presents - A toolkit to produce multi-media interactive display applications for museums, visitor centres, and more
Download from http://pipresents.wordpress.com

JF002
Posts: 94
Joined: Sat Feb 04, 2012 8:49 am
Contact: Website

Re: Play sound (mp3, streams,...) using Python

Tue Aug 28, 2012 9:01 pm

Thanks for these links!

The Python interface to OmxPlayer you are using uses pexpect, right? It means that it is interacting with omxplayer using stdin/stdout?

Do you know if a library exists, that would allow me to call some functions (in C) or to instanciate an object (python or c++)?
My web site : https://codingfield.com

KenT
Posts: 758
Joined: Tue Jan 24, 2012 9:30 am
Location: Hertfordshire, UK
Contact: Website

Re: Play sound (mp3, streams,...) using Python

Wed Aug 29, 2012 7:37 am

yes it uses stdin/out. I'm not sure what you are looking for in the way of a library, probably best to search around the forum, there have been several threads on interfacing omxplayer.
Pi Presents - A toolkit to produce multi-media interactive display applications for museums, visitor centres, and more
Download from http://pipresents.wordpress.com

JF002
Posts: 94
Joined: Sat Feb 04, 2012 8:49 am
Contact: Website

Re: Play sound (mp3, streams,...) using Python

Thu Aug 30, 2012 7:21 pm

I'm searching for a library I can link my code to in order to use Omxplayer in my sofware. In Windows world, I would call that a DLL ;)
My web site : https://codingfield.com

KenT
Posts: 758
Joined: Tue Jan 24, 2012 9:30 am
Location: Hertfordshire, UK
Contact: Website

Re: Play sound (mp3, streams,...) using Python

Sun Sep 02, 2012 3:21 pm

The omxplayer code is here https://github.com/huceke/omxplayer. I'm not an expert on these matters but a library is not required, just call it as a linux command from within your program, but you will need the pipes to pass it commands while it is running at to get its output.
Pi Presents - A toolkit to produce multi-media interactive display applications for museums, visitor centres, and more
Download from http://pipresents.wordpress.com

ghans
Posts: 7878
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Play sound (mp3, streams,...) using Python

Sun Sep 02, 2012 3:44 pm

Omxplayer uses (you may have guessed) the OpenMAX API.
I think there should be Wrappers available for any language , including python.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

JF002
Posts: 94
Joined: Sat Feb 04, 2012 8:49 am
Contact: Website

Re: Play sound (mp3, streams,...) using Python

Sun Sep 02, 2012 4:15 pm

ghans wrote:Omxplayer uses (you may have guessed) the OpenMAX API.
I think there should be Wrappers available for any language , including python.

ghans
No, I didn't guess that... In fact, I know nothing about OpenMAX, but I'll have a look!

In my opinion, communicating with another thread using stdin/stdout is not the best solution. I would rather like using directly the code from OmxPlayer in my code (or linking against omxplayer). It seems to be a cleaner solution to me.

But OpenMAX could be better... I'll try to get some information!
My web site : https://codingfield.com

ghans
Posts: 7878
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Play sound (mp3, streams,...) using Python

Sun Sep 02, 2012 5:53 pm

OpenMAX is a bit hard to work on , i heard.
Perhaps you should look into how ALSA works.
Or you could use aplay or mpg123 (yeah , not a clean solution) .

https://github.com/peterderivaz/pyopenmax can't be the only one .. too lazy to google
more..


ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

MadCow42
Posts: 106
Joined: Sun Jul 01, 2012 12:48 am

Re: Play sound (mp3, streams,...) using Python

Mon Sep 03, 2012 1:55 pm

ghans wrote:Perhaps you should look into how ALSA works.
PyAlsaAudio works fairly well, and is light with few dependencies (but you have to install libaudio2-dev via apt-get)

http://pyalsaaudio.sourceforge.net/

If you have troubles I can send you a code sample of using it, but it's straight forward.

JF002
Posts: 94
Joined: Sat Feb 04, 2012 8:49 am
Contact: Website

Re: Play sound (mp3, streams,...) using Python

Mon Sep 03, 2012 7:58 pm

MadCow42 wrote:
ghans wrote:Perhaps you should look into how ALSA works.
PyAlsaAudio works fairly well, and is light with few dependencies (but you have to install libaudio2-dev via apt-get)

http://pyalsaaudio.sourceforge.net/

If you have troubles I can send you a code sample of using it, but it's straight forward.
I'll have a look to PyAlsaPlay too, thanks for the link!

But for now, i'm trying to build a c++ extension for Python that directly uses omxplayer source code. After a lot (a lot, a lot, a lot) of build errors, I finally heard Airbourne (from a MP3 file) from my Pi ! Victory!

I had to build Ffmpeg, omxplayer, then, learn some Python basics, and learn how to build a Python extension... It's quite interesting :)

I'll keep you up to date when I'll something new !
My web site : https://codingfield.com

Nuker
Posts: 1
Joined: Tue Sep 04, 2012 10:14 am

Re: Play sound (mp3, streams,...) using Python

Tue Sep 04, 2012 10:19 am

Hello,

I've been looking for solution for network streaming, i have 20 tv's/projector in this building.
On tv's there is converter from svideo to analog cable. On projectors we have pc's connected to them.
With pc's there is two solutions - either syncronize the whole playlists (which is ~100gb, constanlty changing) so this method for RPi isn't going to work.
So solution is to play network stream, which i'm desperately waiting for.

Unless you have some suggestions as how i can play videos from network server through RPi

Return to “Python”