By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,985 Members | 1,712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,985 IT Pros & Developers. It's quick & easy.

pygame.mixer.music not playing

P: n/a
Hi,

I am trying to make pygame play music on windows. This simple program:

import pygame,time
pygame.init()
print "Mixer settings", pygame.mixer.get_init()
print "Mixer channels", pygame.mixer.get_num_channels()
pygame.mixer.music.set_volume(1.0)
pygame.mixer.music.load('file1.mp3)
print "Play"
pygame.mixer.music.play()

while pygame.mixer.music.get_busy():
print "Playing", pygame.mixer.music.get_pos()
time.sleep(1)

print "Done"

seems to work. It runs the loop and prints values that look like ms into the
file. After a reasonable time corresponding to the length of "file1.mp3" the
loop is exited and the program ends.

The same thing happens for .mp3 files, .ogg files and .wav files.

Fine. The only problem is that there is no sound :-).

What am I doing wrong? pyGame example games do play sound, but I have not
found an example that uses music.

My ultimate goal is to build a MP3 jukebox that runs on Windows and Linux. I
have chosen pyGame as I am making a graphical Frontend using OpenGL. I have
also tried to look at pymad (which I could not get to work on Windows, no
C-Compiler on this machine and I could not find binaries) and audiere (no
skipping, at least in the python binding. A feature I would like to have.)

Ciao, MM
--
Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.
http://www.marian-aldenhoevel.de
"Wir brauchen keine Opposition, wir sind bereits Demokraten."
Jul 18 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Marian Aldenhövel wrote:
Hi,

I am trying to make pygame play music on windows. This simple program:
import pygame,time
pygame.init()
print "Mixer settings", pygame.mixer.get_init()
print "Mixer channels", pygame.mixer.get_num_channels()
pygame.mixer.music.set_volume(1.0)
pygame.mixer.music.load('file1.mp3)
print "Play"
pygame.mixer.music.play()

while pygame.mixer.music.get_busy():
print "Playing", pygame.mixer.music.get_pos()
time.sleep(1)

print "Done"

seems to work. It runs the loop and prints values that look like ms into the file. After a reasonable time corresponding to the length of "file1.mp3" the loop is exited and the program ends.

The same thing happens for .mp3 files, .ogg files and .wav files.

Fine. The only problem is that there is no sound :-).

What am I doing wrong? pyGame example games do play sound, but I have not found an example that uses music.

My ultimate goal is to build a MP3 jukebox that runs on Windows and Linux. I have chosen pyGame as I am making a graphical Frontend using OpenGL. I have also tried to look at pymad (which I could not get to work on Windows, no C-Compiler on this machine and I could not find binaries) and audiere (no skipping, at least in the python binding. A feature I would like to have.)
Ciao, MM
--
Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.
http://www.marian-aldenhoevel.de
"Wir brauchen keine Opposition, wir sind bereits Demokraten."


Hello Marian,
First thing out i must tell you that pygame is ok for games but the
music quality is sometimes sketchy, you must set the bit rate to get
good sound quality and there are many other pitfalls. Search the net.
You are not the first to try and build a jukebox out of pygame ;)

Py> import pygame
Py> pygame.mixer.init()
Py> pygame.mixer.music.load('c:/everyday.mp3')
Py> pygame.mixer.play()
Py> pygame.mixer.music.fadeout(4000)

You have a typo in the code you posted that may be your problem.
M.E.Farmer

Jul 18 '05 #2

P: n/a
Hi,
Search the net. You are not the first to try and build a jukebox out of pygame ;)
I did find a few, yes.

Currently this is a toy project as I am learning the language, so early
success means more to me than perfect results. And, as I said, I do not really
have an alternative.

Maybe some way to remote control another player would be in order. Leave it
to software that is specialized and all. But I would want something that runs
on Windows and Linux which narrows down my options.
You have a typo in the code you posted that may be your problem.


You are refering to the missing ' in the filename?

pygame.mixer.music.load('file1.mp3)

No, that's not the problem. I did paste working code but I then edited out the
full absolute path that I had coded into the program and introduced the error.

I also tried your sample but no difference. Must be something on my system
as it does seem to play...

Ciao, MM
--
Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.
http://www.marian-aldenhoevel.de
"Wir brauchen keine Opposition, wir sind bereits Demokraten."
Jul 18 '05 #3

P: n/a
Marian Aldenhövel wrote:
Hi,

I am trying to make pygame play music on windows. This simple program:

import pygame,time
pygame.init()
print "Mixer settings", pygame.mixer.get_init()
print "Mixer channels", pygame.mixer.get_num_channels()
pygame.mixer.music.set_volume(1.0)
pygame.mixer.music.load('file1.mp3)
print "Play"
pygame.mixer.music.play()

while pygame.mixer.music.get_busy():
print "Playing", pygame.mixer.music.get_pos()
time.sleep(1)

print "Done"


I tried this exact same code (except the mp3 filename, of course) on my
machine and it worked fine. ActivePython 2.3.4 and Pygame 1.6. Could it
be a hardware problem?

-greg
Jul 18 '05 #4

P: n/a
Marian Aldenhövel wrote:
Maybe some way to remote control another player would be in order. Leave it
to software that is specialized and all. But I would want something that runs
on Windows and Linux which narrows down my options.


Perhaps Zinf?

http://www.zinf.org/

--
Daniel Bickett
dbickett at gmail.com
http://heureusement.org/
Jul 18 '05 #5

P: n/a
Hello again,
Sorry you have had no success. I would suspect it is your system
setup.
Seems the code is working. I didn't think you had the typo problem,
just mentioned it because it says somewhere in the docs that if the
mixer has problems with file loading it would result in a proxy object
that supported the play and stop commands.
Please post your os name and version, Python version, Pygame version,
etc.
Some genius out there might know how to fix it.
Also you can try and look for another sound package, like maybe pyFMOD
;)
Home of FMOD http://www.fmod.org/
and the Python bindings http://sourceforge.net/projects/uncassist
the people who wrote pyFMOD (lots of stuff there)
http://www.cs.unc.edu/~parente/tech/tr01.shtml
Hth,
M.E.Farmer

Jul 18 '05 #6

P: n/a
Hi,
Please post your os name and version, Python version, Pygame version,
German Windows XP Home, 2.3.4, 1.6
Also you can try and look for another sound package


I will. Until I find something suitable I will just build a dummy class
that has the commands I need, I can later interface that to whatever I
really use. Should I ever get to that point - as I said, this is a toy
project and they tend to die suddenly :-).

Ciao, MM
--
Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.
http://www.marian-aldenhoevel.de
"Wir brauchen keine Opposition, wir sind bereits Demokraten."
Jul 18 '05 #7

P: n/a
Hi,
Could it be a hardware problem?


I don't think so. I can play sounds on this machine and I can also play
this very file using Windows Media Player. I suspect it's software, but
I do not know at which level the problem may lie.

Ciao, MM
--
Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.
http://www.marian-aldenhoevel.de
"Wir brauchen keine Opposition, wir sind bereits Demokraten."
Jul 18 '05 #8

P: n/a
Hi,
Perhaps Zinf?


I could not find anything about remote-controlling it. Did not install
it, however.

Ciao, MM
--
Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.
http://www.marian-aldenhoevel.de
"Wir brauchen keine Opposition, wir sind bereits Demokraten."
Jul 18 '05 #9

P: n/a
Just curious what is not suitable about FMOD ?
It seems to be exactly what you are looking for.
Cross platform, free, great sound, python bindings, no compiler needed.
M.E.Farmer

Jul 18 '05 #10

P: n/a
Hi,
Also you can try and look for another sound package, like maybe pyFMOD


I have looked at it. While I do not like some of the boasting on the FMOD
site it does seem very suitable.

FMOD is cross-platform but pyFMOD is available only as Win32-Setup. Does
that mean it cannot be made to work on Linux or is it just not packaged
for it? It looks like your standard DLL-Import-File as known from other
languages and uses ctypes (had to install that first). How hard can it be
to make a version that loads a shared library with the same API on Linux?

To make pyFMOD work with the current version of FMOD I had to fix it in a
few obvious places. After doing so the new version of my micro-program
looks like this:

import time
from pyFMOD import *

res = FSOUND_Init(44100, 32, 0)
print "FSOUND_Init() =", res

stream = FSOUND_Stream_Open("file1.mp3",0,0,0)
print "FSOUND_Stream_Open() =", stream

res = FSOUND_Stream_Play(FSOUND_FREE,stream)
print "FSOUND_Stream_Play() =", res

while True:
print "FSOUND_Stream_GetTime() =", FSOUND_Stream_GetTime(stream)
time.sleep(1)

And plays fine. Now I need to read up on FMODs API to find out how to
eliminate the "while True;" but that should not be a problem. This would give
me a very rich API with full control.

I am having fun! Thank you all.

Ciao, MM
--
Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.
http://www.marian-aldenhoevel.de
"Wir brauchen keine Opposition, wir sind bereits Demokraten."
Jul 18 '05 #11

P: n/a
Very cool,
glad you got it working.
Good job getting it all installed and running so fast.
It won't be long till you have a cool media player of your own.
I have not used PyFMOD yet so can't help with it ( I thought it was
cross platform too **sigh**, at least FMOD is)
Happy hacking,
M.E.Farmer

Jul 18 '05 #12

P: n/a
Hi,
Just curious what is not suitable about FMOD?


Nothing. See my other posting. It just took me some time...

Ciao, MM
--
Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.
http://www.marian-aldenhoevel.de
"Wir brauchen keine Opposition, wir sind bereits Demokraten."
Jul 18 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.