473,695 Members | 2,841 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 16122
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
2815
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
1604
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
1631
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
2073
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
2008
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
5845
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
4415
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
2355
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
11673
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
8555
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
9112
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...
1
8824
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7651
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6484
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
5831
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
4336
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4571
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1970
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.