Playing MP3 from buffer not file January 27, 2009 08:47AM | Registered: 15 years ago Posts: 703 |
MP3Player_Init(); if (connected) { len = net->client_recv(buffer,512); if(len > 0) { if (!MP3Player_IsPlaying()) MP3Player_PlayBuffer(buffer,(s32)len,NULL); } }
Re: Playing MP3 from buffer not file January 27, 2009 10:49AM | Registered: 15 years ago Posts: 22 |
Re: Playing MP3 from buffer not file January 27, 2009 09:12PM | Registered: 15 years ago Posts: 703 |
Re: Playing MP3 from buffer not file January 28, 2009 01:23AM | Registered: 15 years ago Posts: 31 |
#include // standard includes mp3player.h, fat.h, etc won't format correctly in the code block FILE* pFile; long lSize; char * buffer; long result; char * filename; int main() { fatInitDefault(); MP3Player_Init(); if(fatInitDefault()) { filename = (char *)"sd:/music/song.mp3"; OpenFile(filename); } while(1) { if(buffer!=NULL) { MP3Player_PlayBuffer(buffer,lSize,NULL); } } if(buffer!=NULL) { if(MP3Player_IsPlaying()) { MP3Player_Stop(); fclose (pFile); free (buffer); } } return 0; } void OpenFile(char path[50]) { pFile = fopen (path, "rb"); //Check that pFile exist if (pFile!=NULL) { // obtain file size: fseek (pFile , 0 , SEEK_END); lSize = ftell (pFile); rewind (pFile); // allocate memory to contain the whole file: buffer = (char*) malloc (sizeof(char)*lSize); if (buffer == NULL) {fputs (" Memory error",stderr); exit (2);} // copy the file into the buffer: result = fread (buffer,1,lSize,pFile); if (result != lSize) {fputs (" Reading error",stderr); exit (3);} fclose (pFile); } else if (pFile==NULL) { fclose (pFile); //exit (0); } }
Re: Playing MP3 from buffer not file January 28, 2009 03:46AM | Registered: 16 years ago Posts: 70 |
Re: Playing MP3 from buffer not file January 28, 2009 04:45AM | Registered: 15 years ago Posts: 31 |
Re: Playing MP3 from buffer not file January 28, 2009 08:40AM | Registered: 15 years ago Posts: 703 |