I'm making a mp3 player (based in early versions of lightMp3 to play the files) and I'm making the interface with SDL.
While it was only text based interface the app works fine, but after I implemented SDL the app is crashing when going to standby mode. As I searched in the forum the problem maybe is that "it's waiting for threads to sleep", I assume that this is managed by the setupcallbacks funtion, but how can this be fixed???
this is my main loop code (where I play the mp3 and show the interface):
PD:when going into the main loop there is already running the first mp3.
Code: Select all
while(corriendo)
{
sceCtrlReadBufferPositive(&pad, 1);
//////////////////////////////////////////////////////////// STOP/////////////////
if(pad.Buttons & PSP_CTRL_SQUARE && estado==1)
{
MP3_Stop();
estado=0;
MP3_End();
MP3_Init(1);
MP3_Load(actual);
}
//////////////////////////////////////////////////////////// PAUSE ////////////////
else if(pad.Buttons & PSP_CTRL_CIRCLE && estado==1)
{
MP3_Pause();
}
//////////////////////////////////////////////////////////// PLAY ALL ////////////
else if (MP3_EndOfStream() == 1)
{
if(kaux->next!=NULL)
{
MP3_Stop();
estado=0;
kaux=kaux->next;
strcpy(actual,kaux->ruta);
MP3_End();
MP3_Init(1);
MP3_Load(actual);
MP3_Play();
estado=1;
}
else
{
MP3_Stop();
estado=0;
kaux=cabeza;
strcpy(actual,kaux->ruta);
MP3_End();
MP3_Init(1);
MP3_Load(actual);
}
}
//////////////////////////////////////////////////////////// EXIT ////////////////
else if(pad.Buttons & PSP_CTRL_TRIANGLE)
{
break;
}
//////////////////////////////////////////////////////////// PLAY ///////////////
else if(pad.Buttons & PSP_CTRL_CROSS && estado==0)
{
MP3_Play();
estado=1;
}
//////////////////////////////////////////////////////////// PREVIOUS///////////
else if(pad.Buttons & PSP_CTRL_LTRIGGER && kaux->before!=NULL)
{
MP3_Stop();
estado=0;
kaux=kaux->before;
strcpy(actual,kaux->ruta);
MP3_End();
MP3_Init(1);
MP3_Load(actual);
MP3_Play();
estado=1;
}
//////////////////////////////////////////////////////////// NEXT ///////////////
else if(pad.Buttons & PSP_CTRL_RTRIGGER && kaux->next!=NULL)
{
MP3_Stop();
estado=0;
kaux=kaux->next;
strcpy(actual,kaux->ruta);
MP3_End();
MP3_Init(1);
MP3_Load(actual);
MP3_Play();
estado=1;
}
//*****************INTERFACE *******
SDL_BlitSurface(fondo,NULL,pantalla,NULL);
frec=(SDL_Rect) {200,4,275,265};
SDL_SetAlpha(lirica,SDL_SRCALPHA|SDL_RLEACCEL,180);
SDL_BlitSurface(lirica,NULL,pantalla,&frec);
strcpy(aclirica,kaux->lirica);
fd=fopen(aclirica,"r");
if(fd!=NULL)
{
lx=206;
ly=6;
while(!feof(fd))
{
fgets(linea,128,fd);
linea[strlen(linea)-2]=NULL;
frec=(SDL_Rect) {lx,ly,100,10};
txtimg=TTF_RenderText_Solid(fuente,linea,color);
SDL_BlitSurface(txtimg,NULL,pantalla,&frec);
SDL_FreeSurface(txtimg);
ly+=10;
}
showl=1;
}
fclose(fd);
frec=(SDL_Rect) {0,0,100,30};
txtimg=TTF_RenderText_Blended(fuente,kaux->nombre,color);
SDL_BlitSurface(txtimg,NULL,pantalla,&frec);
SDL_FreeSurface(txtimg);
frec=(SDL_Rect) {0,15,100,30};
txtimg=TTF_RenderText_Blended(fuente,"O = pausa",color);
SDL_BlitSurface(txtimg,NULL,pantalla,&frec);
SDL_FreeSurface(txtimg);
frec=(SDL_Rect) {0,30,100,30};
txtimg=TTF_RenderText_Blended(fuente,"X = play",color);
SDL_BlitSurface(txtimg,NULL,pantalla,&frec);
SDL_FreeSurface(txtimg);
frec=(SDL_Rect) {0,45,100,30};
txtimg=TTF_RenderText_Blended(fuente,"L = anterior",color);
SDL_BlitSurface(txtimg,NULL,pantalla,&frec);
SDL_FreeSurface(txtimg);
frec=(SDL_Rect) {0,60,100,30};
txtimg=TTF_RenderText_Blended(fuente,"R = siguiente",color);
SDL_BlitSurface(txtimg,NULL,pantalla,&frec);
SDL_FreeSurface(txtimg);
frec=(SDL_Rect) {0,75,100,30};
txtimg=TTF_RenderText_Blended(fuente,"^ HOME = salir",color);
SDL_BlitSurface(txtimg,NULL,pantalla,&frec);
SDL_FreeSurface(txtimg);
frec=(SDL_Rect) {0,90,100,30};
txtimg=TTF_RenderText_Blended(fuente,"Coded By Soulless",(SDL_Color) {0,0,255});
SDL_BlitSurface(txtimg,NULL,pantalla,&frec);
SDL_FreeSurface(txtimg);
SDL_Flip(pantalla);
}