Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 26th, 2006, 4:24 PM   #1
j3ff86
Newbie
 
Join Date: Mar 2006
Posts: 2
Rep Power: 0 j3ff86 is on a distinguished road
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:
j3ff86 is offline   Reply With Quote
Old Mar 26th, 2006, 4:59 PM   #2
j3ff86
Newbie
 
Join Date: Mar 2006
Posts: 2
Rep Power: 0 j3ff86 is on a distinguished road
Nevermind, I got it work! I suppose reading the examples on the Pygame website helps a lot :o
j3ff86 is offline   Reply With Quote
Old Mar 26th, 2006, 7:57 PM   #3
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to 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!
Sane is offline   Reply With Quote
Old Mar 26th, 2006, 8:29 PM   #4
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
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?
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Mar 26th, 2006, 8:34 PM   #5
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Old Mar 27th, 2006, 12:39 AM   #6
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Google PyMedia.
Arevos is offline   Reply With Quote
Old Mar 27th, 2006, 9:07 AM   #7
Master
Programmer
 
Master's Avatar
 
Join Date: Sep 2005
Location: GA
Posts: 99
Rep Power: 3 Master is on a distinguished road
using api is better and faster
Master is offline   Reply With Quote
Old Mar 28th, 2006, 5:07 PM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Quote:
Originally Posted by Master
using api is better and faster
Er... which API?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 28th, 2006, 8:53 PM   #9
Master
Programmer
 
Master's Avatar
 
Join Date: Sep 2005
Location: GA
Posts: 99
Rep Power: 3 Master is on a distinguished road
MCISendString API from the wimm.dll
Master is offline   Reply With Quote
Old Mar 29th, 2006, 4:08 AM   #10
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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.
Arevos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:34 AM.

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