[Tutor] sound implementation problems
Francois Dion
francois.dion at gmail.com
Thu Jun 13 21:21:45 CEST 2013
I'd start with something simple first, to make sure you have sound output
etc. Run python interactively in the directory you have your wav file. At a
minimum, you need to import pygame, init the mixer (args are not really
needed, but I'll use what you had), set up the sound file and finally, play
it:
>>> import pygame
>>> pygame.mixer.init(22050,-16,2,4096)
>>> snd = pygame.mixer.Sound("bach-cello-suite-1.wav")
>>> music = snd.play()
music will start playing in the background. To check if the music is still
playing:
>>> music.get_busy()
1
>>> music.get_busy()
1
>>> music.get_busy()
0
And that's that. In your code, your run() function was probably a method
taken out of a class where sound returns a filename and seek(0) seeks to
the beginning of a file. You are missing the rest of the class. But, like I
said, you really only need 4 lines to play a wav file.
BTW, nice russian машинистка in the background image of your site.
Francois
--
www.pyptug.org - raspberry-python.blogspot.com - @f_dion
On Thu, Jun 13, 2013 at 1:21 PM, jessica peters <howewriter2000 at yahoo.com>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):
> import pygame.mixer
> pygame.mixer.init(22050, -16, 2, 4096)
> self.sound.seek(0)
> snd = pygame.mixer.Sound(self.sound)
> pygame.mixer.Sound.play("bach-cello-suite-1.wav")
> musicPlaying = True
>
> Any ideas would be appreciated. Thanks.
>
> my website: http://jahowe.com
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130613/d42716e0/attachment-0001.html>
More information about the Tutor
mailing list