We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I am trying to loop a song where when the audio input is at certain level, the volume of the song would be lowered; and when it is retrieved back to normal volume of audio input, the song will continue to play. What I am trying to do now is to mute and unmute the song, but it doesn't seem working...
import ddf.minim.*;
Minim minim;
AudioInput in;
AudioPlayer song;
void setup()
{
size(512, 200);
minim = new Minim(this);
in = minim.getLineIn();
song = minim.loadFile("song.mp3", 1024);
}
void draw()
{
background(0);
stroke(255);
//draw sound line
for(int i = 0; i < in.bufferSize() - 1; i++){
line( i, height/7 + in.left.get(i)*height/7,
i+1, height/7 + in.left.get(i+1)*height/7 );
line( i, height*6/7 + in.right.get(i)*height/7,
i+1, height*6/7 + in.right.get(i+1)*height/7 );
}
if (in.left.level()>0.5){
song.mute();
} else {
song.play();
}
println(in.left.level());
}
Within the if function, I have tried using boolean and song.pause(); and the same issue happened that the whole song would stop playing and wouldn't replay again. I also tried setVolume(); where it said volume is not supported. Hence, I came up with an idea to set the volume to mute and play. But it's still not working...
Answers
Perhaps once an AudioPlayer use mute(), corresponding AudioInput won't get any more level()? :-??
Try out some keyPressed() or mousePressed() user intervention in order to play() it again! L-)
I have actually figured it out, the code works as followed:
Oh, there's unmute() from Controller class too: :))
Anyways, here's a tweaked version of yours: B-)