this is a small program less then 40 lines that is able to play a .mp3 or MIDI file.
In the code, our MP3 file is called "jungle.mp3", be sure to replace the filename within the quotes of "dbLoadMusic()" to play what ever song you want.
The control are:
Spacebar - Start song
Left Arrowkey - Pause song
Right Arrowkey - play song
#include "DarkGDK.h"
void DarkGDK (void)
{
dbSyncOn();
dbSyncRate(30);
int iSP = 0; // stands for "Space Press"
dbLoadMusic("jungle.mp3", 1);
// our main loop
while (LoopGDK())
{
if ((iSP == 0) && dbSpaceKey() == 1) {
dbPlayMusic(1);
dbPrint("Playing \"jungle.mp3\".");
iSP = 1;
}
if ((iSP == 1) && (dbLeftKey() == 1)) {
dbPauseMusic(1);
dbPrint("Music paused.");
iSP = 2;
}
if ((iSP == 2) && (dbRightKey() == 1)) {
dbResumeMusic(1);
dbPrint("Continuing music.");
iSP = 1;
}
dbSync();
}
// Delete the stuff from memory
dbDeleteMusic(1);
return;
}
Originally this thing was supposed to be driven just by the space bar, but im not the best C++ coder, so i need to work on that part, but i still keep the variable "iSP" just for identifying if the song is paused or not.
http://twewy-fan.com/ <-- The first ever fansite for "The World Ends With You"