We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi forums, I'm needing a little guidance with a simple thing here. Not sure if it's a code problem or some of the problems I've been reading about sound files not looping. I have the most up to date sound library and I'm on Processing 3.3.6. The sound files are mp3's. I'm also unsure of the if statements and where I currently have the loop function entered. I basically want this sketch to display the letter that is pressed, and play the sound file associated to it - but loop that sound until another key is pressed, playing another sound file.
Pasting the code here:
import processing.sound.*;
import punktiert.math.Vec;
import punktiert.physics.*;
int x;
int y;
String typedWord = "";
//String[] sounds = {"a"," b", "c"};
SoundFile soundA,soundB,soundC,soundD,soundE,soundF,soundG,soundH,
soundI,soundJ,soundK,soundL,soundM,soundN,soundO,soundP,soundQ,soundR,soundS,soundT;
void setup() {
size(1080 ,720);
soundA = new SoundFile (this, "a.mp3");
soundB = new SoundFile (this, "b.mp3");
soundC = new SoundFile (this, "c.mp3");
}
void draw() {
textSize(100);
background (0);
fill (random (255),random (255),random (255));
text(typedWord, 250, height/2);
}
void keyPressed() {
//println(key);
if (key != 65535) {
if (keyCode == BACKSPACE) {
if (typedWord.length() > 0) {
typedWord = typedWord.substring(0, typedWord.length()-1); //erases the last character
}
}
else {
typedWord += key; //add the key to the word
}
}
}
void keyReleased() {
if ((key == 'a') || (key == 'A')) {
soundA.loop();
}
if ((key == 'b') || (key == 'B')) {
soundB.loop();
}
if ((key == 'c') || (key == 'C')) {
soundC.loop();
}
}
Answers
Please format your code. Edit your post (gear on top right side of any of your posts), select your code and hit ctrl+o. Leave an empty line above and below your block of code. Details here: https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text
I suggest you install the minim library and try playing your files there.
Kf
Formatted - thank you. I want to try with sound lib before trying in minim. Any help is appreciated
Problem solved. Problem was the format of sound files. Changed to mono and lowered the bitrate and works fine now. For ref: original bitrate 128 changed to 32.