Code: Select all
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include "mp3player.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
PSP_MODULE_INFO("Mp3 Player Directory Example", 0, 1, 1);
#define printf pspDebugScreenPrintf
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCall back(cbid);
sceKernelSleepThreadCB();
return 0;
}
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid , 0, 0);
}
return thid;
}
struct songinfo
{ char songname[255];} ;
struct songinfo playlist[100];
int getsonglist(void)
{
int dfd;
SceIoDirent songdir;
memset(&songdir, 0, sizeof songdir);
char buffer[255];
int songcount = 0, maxsongs = 0;
dfd = sceIoDopen("ms0:/PSP/MUSIC/TEST/");
while(sceIoDread(dfd, &songdir) > 0)
{
//sceIoDread(dfd,&songdir);
sprintf(playlist[songcount].songname,"%s",songdir.d_name);
maxsongs = songcount;
songcount++;
} // while sceIODread
sceIoClose(dfd);
return maxsongs;
} // int
int main()
{
pspDebugScreenInit();
SetupCallbacks();
pspAudioInit();
SceCtrlData pad;
char songpathbuf[255];
int songcounter = 1, change = 0, numsong = getsonglist();
MP3_Init(1);
songcounter++;
sprintf(songpathbuf,"ms0:/PSP/MUSIC/TEST/%s",playlist[songcounter].songname);
printf("songpathbuf == %s\n", songpathbuf);
MP3_Load(songpathbuf);
MP3_Play();
while(1) { //wait for X to be pressed
sceCtrlReadBufferPositive (&pad, 1);
if(pad.Buttons & PSP_CTRL_CROSS) break;
if(pad.Buttons & PSP_CTRL_CIRCLE) MP3_Pause();
if(pad.Buttons & PSP_CTRL_RTRIGGER) { change = 1; songcounter++; }
if(pad.Buttons & PSP_CTRL_LTRIGGER) { change = 1; songcounter--; }
if(MP3_EndOfStream() == 1) { change = 1; songcounter++; }
if (change == 1)
{
MP3_Stop();
MP3_FreeTune();
if (songcounter > numsong) songcounter = numsong;
if (songcounter < 1) songcounter = 1;
sprintf(songpathbuf,"ms0:/PSP/MUSIC/TEST/%s",playlist[songcounter].songname);
printf("songpathbuf == %s\n", songpathbuf);
MP3_Load(songpathbuf);
MP3_Play();
change = 0;
} // if change == 1
} // while
MP3_Stop();
//MP3_FreeTune();
sceKernelSleepThread();
return 0;
}
http://forums.qj.net/attachment.php?att ... 2679&stc=1
Anyone know how I could read all the .mp3s from the MUSIC folder and load them using hte library libmad?[/code]