[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] pygame.init before pygame.mixer.init?



 
Hi Clare,
 
    I am curious about this. If you do the mixer.init after the pygame one, place this inside the parens and se if it works. Also, the get_busy can fail if the mode of the mixer is set wrong, and that may be what is going on. If the channel mode is wrong, the busy will never get set true.
 
    I think the pygame.init is erasing all modes for the mixer. So you would have to place the modes in since the pygame.init erased them.
    Try and see if that fixes it. I had a
problem with the get_busy and discovered that might just be the issue.
 
    Insert this into the mixer.init after the pygame init and see if it works.
pygame.mixer.init(21024) # (freq, size, stereo, buffersize)
 
 

# 1=mono, 2=stereo and 1024 buf size, 2050 for 16 bit
pygame.mixer.init(21024) # 2 for stereo and 1024 for Buf Size
----- Original Message -----
Sent: Wednesday, October 10, 2007 5:27 PM
Subject: RE: [pygame] pygame.init before pygame.mixer.init?

I tried running your code and don?t hear anything playing.  I added back pygame.mixer.init() before pygame.init() in your code, and it played.

-- Clare

 


From: owner-pygame-users@xxxxxxxx [mailto:owner-pygame-users@xxxxxxxx] On Behalf Of Ian Mallett
Sent: Wednesday, October 10, 2007 4:18 PM
To: pygame-users@xxxxxxxx
Subject: Re: [pygame] pygame.init before pygame.mixer.init?

 

The simplest thing to do is:

---------------------------------------
import pygame
from pygame.locals import *
pygame.init()
sound = pygame.mixer.Sound("bark.wav")
sound.play()
while pygame.mixer.get_busy ():
   pass
---------------------------------------

...because "pygame.locals" is everything you'll need: the keys module, surfaces, sound, etc.  This way you don't have to do one line of code for every submodule you want to import:

--------------------------------
import pygame.key
import pygame.mixer
import pygame.draw
import pygame.image
import pygame.font
import pygame.mouse
--------------is = to:-------------------
from pygame.locals import *
-------------------------------------------

I recommend doing this.  I've been programming many times and realized that I hadn't imported all the necessary modules.  Opps.  Especially for simplicity, use "from pygame.locals import *"

Anyway, about your question:  Your first line, "pygame.mixer.init()" imports pygame.mixer (you can't init a non-loaded module), and then inits it.  Your next line, "pygame.init()" inits all of the imported modules and pygame.  So, here's what your code is doing:

pygame.mixer.init()  #imports pygame.mixer and inits pygame.mixer
pygame.init ()  #inits all imported modules and pygame. (This re-inits pygame.mixer)

One way to check would be to change the first line:

-----------------------------
pygame.mixer.init()
-----becomes----------
import pygame.mixer
----------------------------

which will still work, but would not init the module, and so would be more efficient.

Ian


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.6/1061 - Release Date: 10/10/2007 8:43 AM