473,728 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pygame.mixer.mu sic not playing

Hi,

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

import pygame,time
pygame.init()
print "Mixer settings", pygame.mixer.ge t_init()
print "Mixer channels", pygame.mixer.ge t_num_channels( )
pygame.mixer.mu sic.set_volume( 1.0)
pygame.mixer.mu sic.load('file1 .mp3)
print "Play"
pygame.mixer.mu sic.play()

while pygame.mixer.mu sic.get_busy():
print "Playing", pygame.mixer.mu sic.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
12 16132
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.ge t_init()
print "Mixer channels", pygame.mixer.ge t_num_channels( )
pygame.mixer.mu sic.set_volume( 1.0)
pygame.mixer.mu sic.load('file1 .mp3)
print "Play"
pygame.mixer.mu sic.play()

while pygame.mixer.mu sic.get_busy():
print "Playing", pygame.mixer.mu sic.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.in it()
Py> pygame.mixer.mu sic.load('c:/everyday.mp3')
Py> pygame.mixer.pl ay()
Py> pygame.mixer.mu sic.fadeout(400 0)

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

Jul 18 '05 #2
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.mu sic.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
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.ge t_init()
print "Mixer channels", pygame.mixer.ge t_num_channels( )
pygame.mixer.mu sic.set_volume( 1.0)
pygame.mixer.mu sic.load('file1 .mp3)
print "Play"
pygame.mixer.mu sic.play()

while pygame.mixer.mu sic.get_busy():
print "Playing", pygame.mixer.mu sic.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
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
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
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
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
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
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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2818
by: AnsNum | last post by:
hello, when I start this program, the movie doesn't play smoothly, anybody has an idea ? (I use windowsXP) import pygame from pygame.display import flip from pygame.locals import * pygame.init()
1
1606
by: JDR | last post by:
Would anyone happen to know of a way to strip out the joystick module of Pygame? I've written a console based application that doesn't need X, mixer, fonts, etc. and I can't get my application to run without X11 libs installed. I've been searching google for the past hour without luck. If anyone knows of any good informational sites, please let me know. I'll keep digging through Python's docs. Thanks!
1
1636
by: maxime | last post by:
Hi, I try to develop a game in python and pygame. In my game I play a music (.mid with pygame.mixer.music) but sometime I need to accelerate it but I don't see how to do that with pygame. Is it possible? If not, do you know an other python music lib that do that? Thanks a lot
10
2079
by: exodus | last post by:
As a fun little task to gain more knowledge of python, i decided to try to mimick the ipod UI with it. here's what i've got so far #!/usr/bin/env python # -*- coding: utf-8 -*- # generated by wxGlade 0.5 on Sat Oct 27 15:46:36 2007 import wx, os, pygame pygame.init() class MyFrame2(wx.MDIChildFrame):
2
2012
by: Woot4Moo | last post by:
Hey guys I am running Windows XP and am having an issue with a game that my team has created. Whenever an audio file is played it creates a very distorted, crackly sound. Any ideas what could be the issue? Thanks
1
5847
by: zswartz | last post by:
Hi All, I've been stuck here for some time now and can't figure this out. If ANYONE can assist me, that would be AMAZING!! I have Windows XP, with Python 25 and Pygame for python 25. I am also coding this in Eclipse ----------------------------------------- My music files are: D:\My Documents\School Work\Comp 523\Projects\MediaPlayer\MediaPlayer\src\MediaPlayer\Music\one.mp3 ----------------------------------------- My Project files...
3
4420
by: globalrev | last post by:
im doing this : http://www.learningpython.com/2006/03/12/creating-a-game-in-python-using-pygame-part-one/ and when closing the program the window stays up and doesnt respond. i tried adding this: http://www.pygame.org/wiki/FrequentlyAskedQuestions bu it doesnt work, or maybe im doing it wrong. heres the code without the added tutorial exit:
1
2357
by: globalrev | last post by:
import pygame pygame.mixer.music.load(example1.mp3) pygame.mixer.music.play(loops=1, start=0.0) Traceback (most recent call last): File "C:\Python25\myPrograms\pygameProgs\musicexp.py", line 3, in <module> pygame.mixer.music.load(example1.mp3)
11
11678
by: globalrev | last post by:
http://www.pygame.org/docs/ref/mixer.html import pygame #pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=3072) //it complained abiout words= so i guess its only the nbrs should be there// pygame.mixer.init(22050, -16, 2, 3072) pygame.mixer.music.load("example1.mp3")
0
8894
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8753
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9411
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9122
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6704
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6012
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2159
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.