MP3's in games can be done!


(asdf_46) #1

I previously posted this on the python form but this is where it should be.

!!!Works with .mp3 and .ogg !!!

Ok, I’ve got a script, or several scripts that will do it. The catch is that you need pygame and to have pygame you will need to have python. This all has to be installed with the correct set path options and there has the be an extra one to point to the pygame directory. That is the hard part. The scripts themselves are quite simple.

(Let me explain a little more about the last paragraph. Python is only need since pygame required it to install. Pygame is really all you need. If you don’t want to install everything I think that only about two files are needed. (The SDL DLL and The libary of cource.) You should be able to drop these files into your working folder with your game.)

To use them just type them out in the text window and set the controller to python and set the script.

#To load music
import pygame.mixer
pygame.mixer.init()
pygame.mixer.music.load(“Your music here.ogg”)

#To play music
import pygame.mixer
pygame.mixer.music.play()

#To stop it
import pygame.mixer
pygame.mixer.music.stop()

#To pause it
import pygame.mixer
pygame.mixer.music.pause() #To unpause change just add un to pause

#To fade out
import pygame.mixer
pygame.mixer.music.fadeout(Time in milliseconds)

#Volume up
import pygame.mixer
from pygame.mixer import *
vol = music.get_volume()
vol = vol + 1 #Subtract to decrease volume
music.set_volume(vol)

There you have it. I will send anyone the sample file if you e-mail me. Hopefully I will soon have a web site I can post this stuff on. asdf_46


(gargola) #2

can it be done with midis and without pygame?


(asdf_46) #3

With out pygame yes, but I think you will still need an outside libary. I’m not familer enough with any of them to tell you what might do it. asdf_46


(gargola) #4

k. thanx :slight_smile:


(saluk) #5

Yeah, I was about to try this, but now I dont have to! I had a hunch that pygame would be required for it to work. WHen I have time next week I’ll see if I can find anything that’s easier to distribute with. Although I suppose you could make it find all the necesary files from a local path, would this be possible?


(asdf_46) #6

Using a local path shouldent be too big a problem. I was playing around with this a little and it looks like you still may have to set the python path. I’ll keeping hacking a little since I think I used to use python by just dumping the lib or libs folder into my blender directory. Thanks for the help in getting this togather. Hopefully by the end of next week I will have a website up that I can host this stuff on. This really still isn’t too bad to get working. I am looking forward to seeing the community use it in most every way except the fact that I am still on dial-up and it will make games bigger. But they will have sound. :wink: asdf_46