Guest User

Untitled

a guest
Jan 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <Audio.h>
  2. #include <SDHCI.h>
  3.  
  4. static void audioErrorCallback(const ErrorAttentionParam *atprm);
  5. bool initializeSound();
  6.  
  7. SDClass theSD;
  8. AudioClass *theAudio;
  9. File soundFile;
  10. bool soundFinished;
  11.  
  12. void setup() {
  13. Serial.begin(115200);
  14. while (!Serial);
  15. initializeSound();
  16. soundFinished = true;
  17. }
  18.  
  19. void loop() {
  20. if (!soundFinished) {
  21. int err = theAudio->writeFrames(AudioClass::Player0, soundFile);
  22. if (err == AUDIOLIB_ECODE_FILEEND) {
  23. soundFinished = true;
  24. stopPlay();
  25. }
  26. } else {
  27. Serial.println("Sleep");
  28. delay(3000);
  29. soundFinished = false;
  30. startPlay();
  31. }
  32. usleep(40000);
  33. }
  34.  
  35. static void audioErrorCallback(const ErrorAttentionParam *atprm) {
  36. if (atprm->error_code >= AS_ATTENTION_CODE_WARNING)
  37. {
  38. Serial.println("Error!");
  39. }
  40. }
  41.  
  42. bool initializeSound() {
  43. theAudio = AudioClass::getInstance();
  44. theAudio->begin(audioErrorCallback);
  45. theAudio->setRenderingClockMode(AS_CLKMODE_NORMAL);
  46. theAudio->setPlayerMode(AS_SETPLAYER_OUTPUTDEVICE_SPHP, AS_SP_DRV_MODE_LINEOUT);
  47. theAudio->initPlayer(AudioClass::Player0, AS_CODECTYPE_MP3, "/mnt/sd0/BIN", AS_SAMPLINGRATE_AUTO, AS_CHANNEL_STEREO);
  48. soundFile = theSD.open("audioFile.mp3");
  49. theAudio->setVolume(-160);
  50. return true;
  51. }
  52.  
  53. void startPlay() {
  54. theAudio->writeFrames(AudioClass::Player0, soundFile);
  55. theAudio->startPlayer(AudioClass::Player0);
  56. }
  57.  
  58. void stopPlay() {
  59. theAudio->stopPlayer(AudioClass::Player0);
  60. // soundFile.close();
  61.  
  62. }
  63.  
  64. Attention: module[5] attention id[2]/code[6] (objects/media_player/player_input_device_handler.cpp L220)
  65. Error!
  66. ERROR: Command (0x22) fails. Result code(0xf1) Module id(0x5) Error code(0x2f) Error subcode(0x0)
  67. ERROR: Command (0x23) fails. Result code(0xf1) Module id(0x5) Error code(0x1)
Add Comment
Please, Sign In to add comment