[Tutor] sound implementation problems

Dave Angel davea at davea.name
Thu Jun 13 19:55:32 CEST 2013


On 06/13/2013 01:21 PM, jessica peters wrote:
> Hi
>
> I'm about 2 yrs into studying Python - started with "Hello World", and I'm working with v 2.5.1 right now.  The past year I've begun trying to write my own interactive fiction.  That works pretty well, but now I'm attempting to put some music into programs (I thought background music would be good), and I'm running into roadblocks.
>
> I've tried several different things for this, and come up with either my text that comes to a halt eventually at an error message (can't read from the files or mixer isn't initialized are the most common ones), or a completely blank screen with no sound.  I've tried both .mp3 files and .wav ones, neither works for this.
>
> Here's the most recent code I've attempted:
>
> import pygame , sys
> import random
> size=[500,500]
> def run(self):

It's not customary to use self as a name in a non-class function.

>      import pygame.mixer
>      pygame.mixer.init(22050, -16, 2, 4096)
>      self.sound.seek(0)

What is the object that has this sound attribute?

>      snd = pygame.mixer.Sound(self.sound)
>      pygame.mixer.Sound.play("bach-cello-suite-1.wav")
>      musicPlaying = True
>

Nobody calls the function, so this file will silently exit.

> Any ideas would  be appreciated.  Thanks.
>

Somebody familiar with both pygame and with sound might be able to help. 
  But you really ought to tell them what version of pygame, and what OS 
you're running on.

And if you get an error message, copy/paste the whole thing, don't 
paraphrase, and show the same code as what was failing.


-- 
DaveA


More information about the Tutor mailing list