Rockbox Development > Starting Development and Compiling

Help with calling rb-> mp3_play_data

(1/1)

snoozydude:
Hello
I have created a function to play an bit of an mp3 file that gets read into a buffer (txt) when I hit a particular value of x and y in the main program.

The actual mp3 file is about 3mb and I just read in a small amount at the moment.

I can get the mp3 excert to play but I do not return from my "play_track" function. The function mp3_is_playing does not return false.

If I remove the calls to mp3_play_data and just put in a counter loop the function works as expected and returns to the main program.

I find I also have to put in a short sleep for rb->mp3_is_playing() to return True.
 
Should mp3_play_data return when it get to the end of the buffer?

Here is an excert of the program - any tips would me much appreciated.

#define BUFFER_SIZE 163840
static unsigned char beep[25];
unsigned char** start;
size_t* size;
static bool is_playing;

/* This is a dummy function to keep mp3_play_data happy  
* copied from chip8.c
*/
void callback(unsigned char** start,size_t* size)
{
*start = beep;
*size = sizeof(beep);
}

short play_track(short x, short y)
{
int fd = -1;
static char txt[BUFFER_SIZE+1];
char *track;

   track="/.rockbox/rocks/games/bob.mp3";
   fd = rb->open(track, O_RDONLY);
 
   if (fd < 0) {
      fd=99;
   }
 
  if (fd == 1) {
      rb->read(fd,txt,BUFFER_SIZE);
      rb->mp3_play_data( txt, sizeof(txt), callback);
  }

  rb->close(fd);
  rb->sleep(HZ);
  rb->yield();

  while( rb->mp3_is_playing() ){
     rb->sleep(HZ);  
  }
 
  x+=1;
  return x;
}

Navigation

[0] Message Index

Go to full version