Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Python (http://www.programmingforums.org/forum43.html)
-   -   Playing sounds in python? (http://www.programmingforums.org/showthread.php?t=9054)

j3ff86 Mar 26th, 2006 5:24 PM

Playing sounds in python?
 
What is the easiest way to play sounds in python? I made a game for a class at school and every time a point is scored, a sound should be played.

I've looked on google and I've found these huge library packages that should let me do it, but I've had no success in getting them to work. Can anyone help me? Thanks :D

:banana:

j3ff86 Mar 26th, 2006 5:59 PM

Nevermind, I got it work! I suppose reading the examples on the Pygame website helps a lot :o

Sane Mar 26th, 2006 8:57 PM

Make sure you're using the functions that let you play all formats of music. Don't make the same mistake I made and use the class for 'wav' formats only!

Dietrich Mar 26th, 2006 9:29 PM

Quote:

Originally Posted by Sane
Make sure you're using the functions that let you play all formats of music. Don't make the same mistake I made and use the class for 'wav' formats only!

How do you play an MP3 file on PyGame?

Sane Mar 26th, 2006 9:34 PM

:

import pygame

pygame.mixer.init()

# play a 'wav' file
sound = pygame.mixer.Sound("my_sound.wav")
sound.play()

# play an 'mp3' file
pygame.mixer.music.load("my_sound.mp3")
pygame.mixer.music.play()


I'm not exactly sure about the mp3 one, because that's what my memory leaves me after 6 months. If it's not that, it'll be something very similar.


The advantages with the 'wav' method is you can preload sound objects and play when required. You can also play upon multiple tracks. mixer.music's only advantage is compatibility with all standard files (midi/mp3...) but you can't create objects or pre-load and/or play multiple sound files.

Arevos Mar 27th, 2006 1:39 AM

Google PyMedia.

Master Mar 27th, 2006 10:07 AM

using api is better and faster

Ooble Mar 28th, 2006 6:07 PM

Quote:

Originally Posted by Master
using api is better and faster

Er... which API?

Master Mar 28th, 2006 9:53 PM

MCISendString API from the wimm.dll

Arevos Mar 29th, 2006 5:08 AM

Quote:

Originally Posted by Master
MCISendString API from the wimm.dll

Which is Windows only, so I'm not sure this would qualify as unequivically "better" than using a cross-platform library such as the build-in SDL media in Pygame, or the general use PyMedia library.


All times are GMT -5. The time now is 5:10 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC