Demo Coding with Pure Basic #03 (Written By Fable Fox)
Playing OGG File
Now let's go for the big one. If you're making a demo, you are obviously going to use MP3 music that you created using Fruity Loops, etc, right? Why don't you use OGG? Some says it's better. Who cares. If I can play a compressed song, I'll be fine. After all, there's no royalty for using OGG file format.
The Easy Way.
Pure Basic supports playing OGG file natively. And by that, it's easy for beginner to use it.
But as far as simplicity goes, this is all what you need to play an OGG file.
InitSound() UseOGGSoundDecoder() LoadSound(0,"techno.ogg") PlaySound(0,1) MessageRequester("Ogg Player","Ogg file is playing...",0)
Four lines is all you need. The fifth is like usual, to keep the application from automatically quitting. Like the MIDI tutorial, when you load a sound, you give it a number, so when you call PlaySound(), the first parameter is the sound you want to play, the second is to loop or not.
0 = play once. 1 = play looping.
Include OGG inside EXE.
Go use pecompiler. Heh.. heh.. Sorry Polaris, just kidding ;-P. OK - that's the last one.
Since Polaris already tought you how to use pecompiler, I'll guess I'll skip that one. For this one, I know who the author for the code is. It's Andre Beer who translated the Pure Basic help files into German. In the file it says Andre. If it's another Andre, next time please use your full name or handle, OK ;-P
InitSound() UseOGGSoundDecoder() L1=?IB2-?IB1 CatchSound(0,?IB1,L1) PlaySound(0,1) MessageRequester("Ogg Player","Ogg file is playing...",0) End IB1: IncludeBinary "techno.ogg" IB2:
This application here reads the OGG file straight from memory. No dumping to disk. Awesome, isn't it. Go Pure Basic go! Most of this code is short and speaks for itself.