![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2006
Posts: 2
Rep Power: 0
![]() |
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 :banana: |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Mar 2006
Posts: 2
Rep Power: 0
![]() |
Nevermind, I got it work! I suppose reading the examples on the Pygame website helps a lot :o
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
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!
|
|
|
|
|
|
#4 | |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Quote:
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
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. Last edited by Sane; Mar 26th, 2006 at 8:47 PM. |
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Google PyMedia.
|
|
|
|
|
|
#7 |
|
Programmer
Join Date: Sep 2005
Location: GA
Posts: 99
Rep Power: 3
![]() |
using api is better and faster
|
|
|
|
|
|
#8 | |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Quote:
|
|
|
|
|
|
|
#9 |
|
Programmer
Join Date: Sep 2005
Location: GA
Posts: 99
Rep Power: 3
![]() |
MCISendString API from the wimm.dll
|
|
|
|
|
|
#10 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|