Hello i make this small program to listen mp3 music from text file
but it crash after a fiew hours if i put over 500 songs in text file
my problem is i run out of memory
here is this small program
#include <SDL.h>
#include <smpeg/smpeg.h>
#include
#include
#define NEXTM 180 // next music
using namespace std;
SDL_Surface * screen;
SMPEG *mpeg;
SMPEG_Info info;
SDL_Event event;
int done;
int main(int argc, char * argv[])
{
if(SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO ) < 0) {
cout << “Unable to init SDL” << endl;
exit(1);
}
screen = SDL_SetVideoMode(300, 200, 24, SDL_SWSURFACE);
if ( screen == NULL ) {
cout << "Couldn't set video mode" << endl;
exit(1);
}
ifstream music_in (“Data/mp3text”, ios::in);
if(!music_in) {
cout << “cannot open mp3text.\n”;
return 1;
}
char musicin[250];
musicin[250] = ‘\0’;
time_t lasttimem = time(NULL)-NEXTM;
while (!done & !music_in.eof()){
if (time(NULL)>lasttimem+NEXTM){
if (mpeg == NULL) {
}
else if (mpeg){
//free(mpeg);
SMPEG_delete(mpeg);
cout << "Delete: " << musicin << endl;
}
music_in.getline(musicin, 239);
mpeg = SMPEG_new(musicin, &info, 1);
SMPEG_enableaudio(mpeg, 1);
SMPEG_setvolume(mpeg, 100);
if (info.has_audio){
printf("Now play: %s: MPEG audio stream\n", musicin );
if (info.has_audio)
printf("\tAudio %s\n", info.audio_string);
if (info.total_size)
printf("\tSize: %d\n", info.total_size);
if (info.total_time)
printf("\tTotal time: %f\n", info.total_time);
SMPEG_play(mpeg);
}
lasttimem = time(NULL);
}
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
done = 1;
else if (event.type == SDL_KEYDOWN)
{
if (event.key.keysym.sym == SDLK_ESCAPE)
done = 1;
else if (event.key.keysym.sym == SDLK_s)
SMPEG_stop(mpeg);
else if (event.key.keysym.sym == SDLK_p)
SMPEG_play(mpeg);
}
}
}
SMPEG_stop(mpeg);
SMPEG_delete(mpeg);
return(0);
}
why i run out of memory? help pls.
BTW: in info.total_time i see the time like this " Total time:
230.416750"
how can i see in seconds
ppap_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*
http://join.msn.com/?page=features/virus