Page 1 of 1

Streaming music off of mp3/ogg files

Posted: Sun Jun 15, 2014 10:41 am
by TheCodingBrony
I couldn't find any examples on how to play mp3/ogg files without having to load such files entirely into memory (in other words, streaming)... There is this MP3Player_PlayFile() function in mp3player.h but I can't find any information on how to use it.

Any useful help will be greatly appreciated.

Re: Streaming music off of mp3/ogg files

Posted: Mon Nov 10, 2014 4:22 am
by emu_kidid
Use this one which takes a callback that is called whenever more data is necessary:

Code: Select all

s32 MP3Player_PlayFile(void *cb_data,s32 (*reader)(void *,void *,s32),void (*filterfunc)(struct mad_stream *,struct mad_frame *));

int mp3Reader(void *cbdata, void *dst, int size) {
        FILE *file = cbdata;
        return fread(dst,1,size,file);
}

void play() {
        FILE *myFile = fopen("sd:/music.mp3");
        MP3Player_PlayFile(myFile, &mp3Reader, NULL);
        fclose(myFile);
}