How come the sounds won't reload in "paths" code (but images do?)

edited December 1 in Library Questions

Hello,

I am a teacher helping my students complete their projects for a 12th grade exhibition. In this project, there are 4 roll-over photos and sounds in path 1. When we cycle through to path 0 and then path 1 again, the photo roll-overs work but the sounds don't. Looking for advice - thank you!!!

PImage photo1;
PImage photo2;
PImage photo3;
PImage photo4;
PImage photo5;
PImage photo6;
PImage photo7;
PImage photo8;

int path = 0;

import ddf.minim.*;
Minim minim;
AudioPlayer thunder;
AudioPlayer thunder2;
AudioPlayer thunder3;
AudioPlayer thunder4;


void setup(){
  size (1000,700);
  photo1 = loadImage ("StartScfinal.png");
  photo2 = loadImage ("goodcopbadcop.png");
  photo3 = loadImage ("stereotypes.png");
  photo4 = loadImage ("goodcopbadcopfettyfettywap.png");
  photo5 = loadImage ("goodcopbadcophatecrimes.png");
  photo6 = loadImage ("goodcopbadcopsikhsikh2.png");
  photo7 = loadImage ("latinomanlm.png");
  photo8 = loadImage ("newbolt.png");

 minim = new Minim(this);
 thunder = minim.loadFile ("thunderthunder.mp3");
    thunder2 = minim.loadFile ("thunderthunder2.mp3");
      thunder3 = minim.loadFile ("thunderthunder3.mp3");
       thunder4 = minim.loadFile ("thunderthunder4.mp3");

}

  void draw(){
    println(mouseX,mouseY);
    println ("path=",path);

    if (path == 0) {
      imageMode(CENTER);
      image (photo1,500,350);
      cursor (HAND);
    if ((mousePressed) && (mouseX > 178) && (mouseX < 805) && (mouseY > 524) && (mouseY < 593)){
      path = 1;
    }
    }
    if (path == 1) {
      cursor(photo8);
    {
      image (photo2,500,350,1000,700); 
      imageMode(CENTER);
  }
    if ((mouseX > 153) && (mouseX < 250) && (mouseY > 402) && (mouseY < 578)){ 
      thunder.play();
      image (photo6,500,350,1000,700); 
  }
    if ((mouseX > 541) && (mouseX < 612) && (mouseY > 373) && (mouseY < 544)){
      image (photo4,500,350,1000,700);
      thunder2.play();
  }
    if ((mouseX > 912) && (mouseX < 969) && (mouseY > 384) && (mouseY < 539)){  
      image (photo7,500,350,1000,700);
      thunder3.play();
  }
    if ((mouseX > 820) && (mouseX < 881) && (mouseY > 375) && (mouseY < 575)){  
      image (photo5,500,350,1000,700);
      thunder4.play();

    }

  }
  if (path == 1) {
    if (keyPressed == true){
      path = 0; 
    }
  }
}

Answers

  • Answer ✓

    Samples are like bits of tape, you need to rewind() them before they play again...

  • edited December 1

    Hi @Koogs,

    That makes a lot of sense. And works well with the code. Thank you!

  • edited December 2

    So yeah, already a good answer here.
    Just a side note:
    AudioPlayer thunder;
    AudioPlayer thunder2;
    thunder2 thunder3 is a new Object of an Audioplayer you know from your Desktop. So you open different tracks in different audio player Objects
    alt text

    The Problem here is that with Minim you still have a singel AudioBus output (your monitor etc. Speakers), not like with Processing Images ( they can have multiple Speakers, the Window, in terms of Audio its a mixing console ) so every Object is listening to the same Audio Bus, that is why you can't here anything.

    Usually you want to have a Playlist in just one singel Player Object.

    alt text


    Here you can here all audio played simultaneously 1 singel Audioplayer different tracks

    import ddf.minim.*;
    Minim minim;
    void setup() {
      size (200, 200);
      minim = new Minim(this);
    }
    int a =0;
    // no check if file is loaded just wait few sec.
    void draw() {
     if (mousePressed) minim.loadFile(new String[] {
      "https://"+"github.com/ddf/Minim/raw/master/examples/Basics/AnalyzeSound/data/jingle.mp3", 
      "https://"+"ia600203.us.archive.org/2/items/Thunder_849/Thunderstorm1.mp3", 
      "https://"+"github.com/ddf/Minim/raw/master/examples/Basics/DrawWaveformAndLevel/data/groove.mp3"
    }[(a==2)?a=0:++a]).play();
    }
    

    If your solution is working for you - fine. Otherwise you need the start and stop position of the singel tracks, like in a real AudioMediaPlayer.
    Just want to point this out.

    EDIT: maybe i get also something wrong, and the bug is elsewhere also working

    void draw() {
    if (mousePressed) {
      thunder=  minim.loadFile(scr[0]);
      thunder2=  minim.loadFile(scr[1]);
      thunder.play();
      thunder2.play();
      }
    }
    

    EDIT 2: i confused myself with the loading time from web. i think.

  • @nabr that is a really helpful expansion of how the player works - thank you!!!!

Sign In or Register to comment.