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

Re: [pygame] playing sound on Windows



I don't know why this problem is happening, but I can reproduce it.

I tested your script (with my own 0.wav file) and it worked fine on 
Linux, but on Windows 7 (64 bit) with both python 2.6 + pygame 1.9.1 and 
python 2.7 and pygame 1.9.2 there is no sound.

Although this does not solve your problem, I think you should remove the 
pygame.mixer.pre_init() because inside the class but not inside a 
function is definitely the wrong place for it, and even if you move it, 
all it does is change the defaults for pygame.mixer.init() to the same 
values those defaults have already.

You can also add

   print pygame.mixer.get_init()

and it will display the settings with which the mixer was initialized, 
or if mixer init failed entirely it will return None.

When I tested, .get_init() returned (22050, -16, 2) indicating that the 
init succeeded with the default settings.

Before I tested your script on my windows box, I tested my 0.wav file in 
audacity and it sounded fine.

After I tested your script, and the sound failed to play, I tried it 
again in audacity, and then it would not play.

Even though I could not get the .wav file to play anymore either in 
python or in audacity, the windows volume mixer test sound still worked 
find.

Very strange.

On Thu, Jun 27, 2013 at 01:04:12PM -0300, sarah marques wrote:
> Yes, I meant that. Sorry, I translated my code from Portuguese to send
> it to the list, and this word 'som' slipped.
> 
> Sarah Barreto Marques
> 
> 2013/6/27, James Paige <Bob@xxxxxxxxxxxxxxxxxxx>:
> > On Thu, Jun 27, 2013 at 08:11:39AM -0700, sarah wrote:
> >> Hi all,
> >> I've just subscribed to this list hoping someone can hplease elp me with
> >> the
> >> following problem: I wrote the class bellow (I also attached it) that
> >> simply plays a sound
> >> file when its method play_file() is called. It works on Linux perfectly,
> >> but
> >> on Windows, no sound is played and I do need to find the reason of it.
> >> Configurations are:
> >> Windows 7 (32 bits), Python 2.6 and Pygame 1.9.1 (win32). Thank very
> >> much for any help!
> >> Sarah Barreto Marques
> >>
> >> www.audiogames.com.br
> >> @sarahbmarques
> >>
> >>
> >>
> >>
> >> import sys, pygame
> >> import time
> >>
> >> class Sound:
> >>     pygame.mixer.pre_init(frequency=22050, size=-16, channels=2,
> >> buffer=1024)
> >>
> >>     def play_file(self, name):
> >> #        pygame.mixer.pre_init(frequency=44100, size=-16, channels=2,
> >> buffer=1024)
> >> #        pygame.mixer.get_init()
> >>         sound=pygame.mixer.Sound(name)
> >>
> >>         print 'playing'
> >>         sound.play()
> >>
> >>         print 'done'
> >>         time.sleep(2)
> >>         return sound
> >>
> >> if __name__=='__main__':
> >>     pygame.init()
> >>     sound=Sound()
> >>     som.play_file('0.wav')
> >
> >
> > did you mean:
> >
> >   sound.play_file('0.wav')
> >
> > in the last line? som does not seem to be defined anywhere.
> >
> > ---
> > James Paige
> >
>