if (file.isPlaying()) {
i++;
println("File play " + i + "i-seconds");
} else {
i = 0;
}
if(i>10){
file.stop();
}
}
Above left an example code. If you start (by pressing) the audio, then everything works, but if you repeat it many times, the sound starts to make noise very stylish.
The example shows that I tried to stop it forcibly. This did not work.
For the test, any files are suitable for you, since for me this happens even with examples from the library.
If you want to avoid the overlap when you press the mouse then you should check if the audio is not already playing first, and if it is not then play the audio.
if (mousePressed) {
if(!file.isPlaying()) {
file.play();
}
}
If you are wanting to restart the audio when you press the mouse then you should check if the audio is playing, and if it is then stop() the audio followed by play(), else play()`.
if (mousePressed) {
if (file.isPlaying()) {
file.stop();
file.play();
} else {
file.play();
}
}
when I saw your answer, I was delighted, thinking that the problem would be solved. because by all laws of logic the answer is correct
But after adding your solution to the code, nothing changed.
After many clicks and starting the sound, the sound began to make noise again. And with each press, the noise becomes stronger.
I can’t even guess what it is.
Moreover, there are lags when compiling the code, and if the code is made by the application.
The reason is not in the code, since the problem occurs even in the examples of the sound library (without changing the code).
Your help is really needed, how can I help you (so that you help me) besides the code? After all, I did not use sound in the project, but just opened an example from the library.
Could be your soundcard or some other hardware related issue, maybe. ¯_(ツ)_/¯
I don’t see a sketch in the examples that match the code you shared above …
Can you share the updated code? Simply saying you added the code and there is no change doe not really help, maybe you put it outside of a function, have syntax errors, ect …
Maybe the issue I think you are having is not the issue at all. To me it sounds like you are describing the audio overlapping, meaning each time you press the mouse it plays a new instance of the audio, while the other instance(s) are still playing.
Is this the issue?
If so, then my previous answer is the solution, if not then can you please share your updated code with a more detailed description of what the issue is?
If this is really that important, then here is the code I’m using
At the same time, I added a counter to understand when the sound begins to break itself.
At 95-100 presses, the sound becomes incorrect. And with each subsequent press, this effect increases.
import processing.sound.*;
SoundFile file;
int i = 0;
Sorry, I was distracted, the issue is using mousePressed …
If you use the mouseClicked() you can set a boolean to true, then check if that boolean is true in your logic and stop/play the sound then set the boolean to false.
Mouse click does not solve the problem.
There is a suggestion that this is a regular problem APDE. Faced with it when APDE did not capture the pressing of the keyboard of Russian letters.
Can you test with yourself? Or is everything OK in your APDЕ?
Because mousePressed is true while it is pressed, causing the audio to stop and play each frame during the press. Although you press and release quickly, it still fires repeatedly for several frames.
If you click on the Play Sound a hundred times, and when the lags start … You can write soundFile=null and then set the sound file again.
Spoiler: this does not solve the problem. but it doesn’t give any errors, which means that at the time of zeroing the sound, it does not play anywhere.