how to make an audio loop without going back to the beginning of the track after being paused
in
Core Library Questions
•
3 years ago
Hi there,
I have a song that is playing and when the mouse is pressed the song pause and a 2nd sound is played during the pause. When the mouse is released the song start playing again but from the beginning of the track, is a way to make the song continue from where it was paused? I tried using 'song.play();' after 'void mouseReleased()' which works but the song doesn't loop back to the beginning of the track once the whole song has been played.
Ideally I would like to make the song continue after it has been paused by mousePressed/ the 2nd sound but also to have the song looping once it reach the end of the track.
I hope I make sense. If someone have any feedback that would be very helpful.
Here is my code
import ddf.minim.*;
import ddf.minim.AudioSample.*;
Minim minim;
AudioPlayer song;
AudioSample [] sounds = new AudioSample [3];
void setup(){
size(100,100);
minim = new Minim(this);
song= minim.loadFile("delin.wav");
song.loop();
sounds [0] = minim.loadSample("aha.wav");
sounds [1] = minim.loadSample("oh.wav");
sounds [2] = minim.loadSample("argh.wav");
}
void draw()
{
}
void mousePressed(){
song.pause();
int index = int (random(0,3));
sounds[index].trigger();
}
void mouseReleased(){
song.loop();
}
void stop(){
song.close();
minim.stop();
super.stop();
}
2