LittleFS -> I2S | How do I trigger looping for specific files? #914
-
`/**
#include "AudioTools.h" const char startFilePath="/"; void printMetaData(MetaDataType type, const char* str, int len){ void setup() { // setup output // setup player void loop() { Hi, I want to try working on a project that is similar to this https://www.youtube.com/watch?v=3YmMNpbFjp0 I've read the documentation for AudioPlayer https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_audio_player.html#af62138cf6d06e41ae7d0535e4ecdeeb2 and I don't understand
|
Beta Was this translation helpful? Give feedback.
Replies: 15 comments 10 replies
-
I found the setLoop setLoop function along with MemoryStream, but how do I integrate that with my LittleFS setup, and how do I change the file being played with filefilter for different buttons? |
Beta Was this translation helpful? Give feedback.
-
Please read the Wiki about the AudioPlayer: From my point of view it contains all the information and I don't think there is anything to add... |
Beta Was this translation helpful? Give feedback.
-
I'm assuming you referred to this page https://github.com/pschatzmann/arduino-audio-tools/wiki/The-Audio-Player-Class#file-based-audio-sources with the class for littleFS https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_audio_source_little_f_s.html I don't see any method to loop it. I'm looking at the https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_file_loop.html file loop class right now but how to I pass it along into the AudioPlayer player variable I've defined? |
Beta Was this translation helpful? Give feedback.
-
Here is the relevant information: |
Beta Was this translation helpful? Give feedback.
-
Just so I understand this right: AudioPlayer is the main class that's doing all the work, which the constructor takes in an AudioSource class(LittleFS), AudioOutput class(I2S), and AudioDecoder class(MP3). I'm sorry I still don't understand how can I insert FileLoop into the equation. I tried finding for an example with FileLoop in the /examples directory but I couldn't seem to find one. I've spent a couple of hours trying other different methods (calling player.begin() again after a set delay which kinda works??? but not ideal), and looking at past discussions #724 And also I'm confused about how this example works: There the AudioPlayer.copy() method is not called in the loop but just a simple check is done, how is it still able to play the full mp3 file? void loop(){ The documentation (https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_audio_player.html) here states that I have to call the copy() method inside the loop for the AudioPlayer class to work properly. Thanks for reading and answering me earlier, this library is cool. Is it possible you can help to write one line of how FileLoop can be passed to the AudioPlayer class it would be really helpful for me, just the passing method, how do I pass the FileLoop to AudioPlayer. Thank you! |
Beta Was this translation helpful? Give feedback.
-
I am afraid you still don't understand: Just implement your own AudioSource logic! All you need to do is to implement the nextStream method to return a Stream (=File) that makes sense in your case (dependent on what button was pressed). You could return a FileLoop but this is not really necessary as when you return the same file, it is automatically playing again However if I would implment your requirement, I would not use the player at all, but just build my own logic using directly multiple FileLoop objects as copy source. I would even replace the files with a MemoryStream to simplify things even further... |
Beta Was this translation helpful? Give feedback.
-
`/**
#include "AudioTools.h" const char startFilePath="/"; void printMetaData(MetaDataType type, const char* str, int len){ void setup() { // setup output // setup player void loop() { do you have any idea why on the serial monitor it spams: |
Beta Was this translation helpful? Give feedback.
-
Okay, it seems to spam that if player.begin() is called after player.stop() Does player.stop() act as killing the AudioPlayer entirely and not just a graceful stop playing, but still allow for playing later on? |
Beta Was this translation helpful? Give feedback.
-
I'm able to replicate this using this bare minimum code `/**
#include "AudioTools.h" enum {itsStopped, itsPlaying}; const char startFilePath="/"; void printMetaData(MetaDataType type, const char* str, int len){ void setup() { // setup output // setup player void loop() { If I pull down GPIO 33 (player.stop()), then pull down GPIO2 (player.begin()), nothing gets played and instead my serial monitor is spammed with [I] Fade.h : 104 - faded out 576 frames to volume 0.000000 |
Beta Was this translation helpful? Give feedback.
-
Don't paste code w/o proper formatting: this is impossible to read! |
Beta Was this translation helpful? Give feedback.
-
I apologise for the formatting issues. I tried this with a delay instead of pushbuttons to remove any possible debouncing and still encountered this issue. The following code executes player.begin() in the setup function, and alternates between player.stop() and player.begin() every 5 seconds in the loop function. The program runs perfectly from 0 to 5 seconds, and stops correctly from 5 to 10 seconds, but at the 10 second mark, I still encounter the same issue with [I] Fade.h : 104 - faded out 576 frames to volume 0.000000 being spamming in my console and the audio jittering and not playing correctly when subsequent times player.begin() gets called after the first player.stop(). Please refer to the below minimal reproducible code, and here's a link to the pastebin of the serial monitor output: https://pastebin.com/69pFGcbc
|
Beta Was this translation helpful? Give feedback.
-
The opposite of stop() is play() and not begin()! Alternativly you can use setActive(false) and setActive(true); If fading is not important to you you can alternatively just stop and resume calling copy() |
Beta Was this translation helpful? Give feedback.
-
Okay, I have rewrote the code to call play() instead of begin(). It seems to not like that begin() is being called more than once, maybe I misunderstood the documentation. In any case, is there a way to replay from the beginning again? Do I declare |
Beta Was this translation helpful? Give feedback.
-
isActive() seems to only return false when stop() is explicitly called, even though StreamCopy.h reached the end of file and nothing is being played. Is there a way to check if AudioPlayer is not playing anything? |
Beta Was this translation helpful? Give feedback.
-
Thank you |
Beta Was this translation helpful? Give feedback.
I am afraid you still don't understand: Just implement your own AudioSource logic! All you need to do is to implement the nextStream method to return a Stream (=File) that makes sense in your case (dependent on what button was pressed).
You could return a FileLoop but this is not really necessary as when you return the same file, it is automatically playing again
However if I would implment your requirement, I would not use the player at all, but just build my own logic using directly multiple FileLoop objects as copy source. I would even replace the files with a MemoryStream to simplify things even further...