Audio not working!

edited March 2018 in Library Questions

Hi guys, I'm super new to Processing so the solution is probably something obvious.

I'm trying to create a sketch which wouldplay a show a different image and play a different song depending on where the mouse is positioned. I managed to write a code which would work depending where the mouse is pressed. So i decided to use that same code but to try and make it work depending on where the mouse is postioned. But when i took away the "void mousepressed' function and joined the code into "void draw" only the images change with the position of the mouse, the audiofiles don't really play... Only the first couple of seconds of the first audio plays before restarting itself and whenever I move the mouse around i can hear random low noises (i guess of the audios trying to play, i'm not sure). I'm super confused by this and would be grateful if anyone could help me!

Tagged:

Answers

  • edited March 2018

    Here is my code:

    PImage img;

    import ddf.minim.*;

    AudioPlayer player;

    Minim minim;

    void setup() {

    size(600, 400);

    img = loadImage("image1.jpg");

    img = loadImage("image2.jpg");

    img = loadImage("image3.jg");

    img = loadImage("image4.jpg");

    img = loadImage ("image5.jpg");

    minim = new Minim(this);

    player = minim.loadFile("audio1.mp3");

    minim = new Minim(this);

    player = minim.loadFile("audio2.mp3");

    minim = new Minim(this);

    player = minim.loadFile("audio3.mp3");

    minim = new Minim(this);

    player = minim.loadFile("audio4.mp3");

    minim = new Minim(this);

    player = minim.loadFile("audio5.mp3");

    }

    void draw() {

    image(img, 0, 0, width, height);

    if(mouseX<width/5) {

    if (player.isPlaying()) {
    
      player.close();}
    
      player = minim.loadFile("audio1.mp3");
    
      player.play();
    
      img = loadImage("image1.jpg");
    
      stroke(0);
    

    }

    else if (mouseX<width/4) {

    if(player.isPlaying()) {
    
      player.close();}
    
      player= minim.loadFile("audio2.mp3");
    
      player.play();
    
      img = loadImage("image2.jpg");
    
      stroke(0);
    

    }

    else if(mouseX<width/3){

    if(player.isPlaying()) {
    
      player.close();}
    
      player = minim.loadFile("audio3.mp3");
    
      player.play();
    
      img = loadImage("image3.jpg");
    
      stroke(0);
    

    }

    else if (mouseX<width/2) {

    if(player.isPlaying()) {
    
      player.close();}
    
      player = minim.loadFile("audio4.mp3");
    
      player.play();
    
      img = loadImage("image4.jpg");
    
      stroke(0);
    

    }

    else if (mouseX<width/1) {

    if(player.isPlaying()) {
    
      player.close(); }
    
      player = minim.loadFile("audio5.mp3");
    
      player.play();
    
      img = loadImage("image5.jpg");
    
      stroke(0);
    

    }

    else {

    println("void click");
    

    }

    }

    void stop() {

    player.close();

    minim.stop();

    super.stop();

    }

Sign In or Register to comment.