Audio Player DLL

Well this project involves a lot of things that definitely are
entertaining. It started as a Audio Playing DLL. Vague? You bet.
Anyway, this DLL is nothing more than an MP3 player or was. I started
writing and got more excited everytime and eventually I decided to make
it compatible with XPCOM, and use it to play audio through mozilla.
I actually wrote that piece of code and its stashed somewhere!

Anyway, it was becoming more like a kludge than a library. So I decided
to rewrite it entirely. I separated the code a lot in order for it to become
sort of modular. Now you can actually play OGG's aswell. Can add any
other type of sound aslong as you rewrite the 5 routines required.

Here is how it currently works:

  1. #include "AudioDecoderEngine.h"
  2. #include "MP3Library.h"
  3. #include <windows.h>
  4. #include <stdio.h>
  5. #include <time.h>
  6. /* This callback only works on MP3s */
  7.  
  8. void callback(void * data, status ourStatus, void * user_data) {
  9.  
  10. pfData ourData = (pfData)data;
  11. pmp3data innerData = (pmp3data)ourData->extraFileData;
  12.  
  13. static int calls = 0;
  14.  
  15. if (calls++ < 1 && ourStatus != STATUS_CLOSING)
  16.  
  17. fprintf(stdout, "Layer[%s] Mode[%s] Emphasis[%s]\n\r",
  18. MP3Layer[innerData->layer],
  19. MP3Mode[innerData->mode],
  20. MP3Emphasis[innerData->emphasis]);
  21.  
  22.  
  23. switch(ourStatus)
  24. { case STATUS_CLOSING:
  25. break;
  26.  
  27. case STATUS_OPENING:
  28. break;
  29. case STATUS_PLAYING:
  30. fprintf(stdout,"%d%%\r",
  31. (ourData->currentFrame*100) / ourData->totalFrames );
  32.  
  33. break;
  34. case STATUS_DONE:
  35. fprintf(stdout, "done playing\n\r");
  36.  
  37. calls = 0;
  38. break;
  39. }
  40. }
  41.  
  42. int main(int argc, char **argv)
  43. {
  44.  
  45. PAudioLib audio =
  46. AUDIO_INIT("D:\\Dream Theater - Another Day.mp3", NULL, callback)
  47.  
  48. int i;
  49. AUDIO_LOAD(audio)
  50. AUDIO_PLAY(audio, 0)
  51.  
  52. while(audio->playing)
  53. {
  54. Sleep(2000);
  55.  
  56. }
  57.  
  58. AUDIO_STOP(audio)
  59. AUDIO_CLOSE(audio)
  60. return 0;
  61.  
  62. }

I am still working on it. I assume its thread safe but I really haven't
checked that thoroughly. Feel free to download and try it out.

Tags: