Minim: know when a song is done
in
Core Library Questions
•
1 year ago
Hey I'm building an app in processing that is currently utilizing the minim library to play some sounds. There's a list of sounds and they loop 1 after the other. the looping and playing work just fine what I have a question about is finding a good method of knowing the song is done. currently I have it setup to check the length() of the AudioPlayer - the position() of the AudioPlayer, thinking if length - position == 0, we are done.
Well that doesnt quite work, it seems the songs have a varying amount of time on the ends that are not played. IE length() - position will decrease until it hits like 265 and not go down anymore as the song is done. This number varies from 265 all in to the 500s as I have seen.
Does Minim allow or have an event somewhere that is fired when a song is done playing?
Heres some sample code of what I have so far :
Well that doesnt quite work, it seems the songs have a varying amount of time on the ends that are not played. IE length() - position will decrease until it hits like 265 and not go down anymore as the song is done. This number varies from 265 all in to the 500s as I have seen.
Does Minim allow or have an event somewhere that is fired when a song is done playing?
Heres some sample code of what I have so far :
- //called in setup()
- void setupSongs() {
- songFiles = new AudioPlayer[ardPins.length];
- String filePrefix = "sound";
- for (int i = 1; i<=songFiles.length; i++) {
- songFiles[i - 1] = m.loadFile(filePrefix + str(i)+".mp3", 1024);
- }
- }
- void draw() {
- if ((songFiles[currSong].length() - songFiles[currSong].position()) <= 800) {
- println("song done next song");
- songFiles[currSong].pause();
- songFiles[currSong].rewind();
- int nextSongNum = currSong + 1;
- currSong = nextSongNum % songFiles.length;
- songFiles[currSong].play();
- }
- }
1