Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Mar 29th, 2006, 9:04 AM   #11
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
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.
Thanks Sane,
on the mp3 file ( I put one in I had) I get the following error message:
pygame.error: Module format not recognized
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Mar 29th, 2006, 10:27 AM   #12
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 Arevos
Google PyMedia.
Did that and installed PyMedia, note that I use Windows XP (all I have!).
However:
# PyMedia wave play (from the tut examples)
# download: pymedia-1.3.5.0-pre2.win32-py2.4.exe
# free from: http://pymedia.org/
# works not well!!!! just noise!!!!

import pymedia.audio.sound as sound
import time, wave

def playWAV( fname ):
    f = wave.open( fname, 'rb' )
    sampleRate = f.getframerate()
    channels = f.getnchannels()
    format = sound.AFMT_S16_LE
    print sampleRate, channels, format  # test => 8000 1 16
    snd1 = sound.Output( sampleRate, channels, format )
    s = ' '
    while len(s):
        s = f.readframes( 1000 )
        snd1.play( s )

    # sound module is not synchronous, want everything to be played before exit
    while snd1.isPlaying(): time.sleep( 0.05 )


if __name__== '__main__':
    waveFile = 'boing.wav'  # put in a wave file you have
    playWAV(waveFile)
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Mar 30th, 2006, 12:41 AM   #13
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
It might be possible that the reason PyGame doesn't play MP3s natively is due to the same licensing issues that plague Linux. Maybe you just need the right libraries, or perhaps an Ogg will work better.

Regardless, I'll look into it when I get back from work, as I'd like to know as well.
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 7:57 PM.

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