Vince
Vince

Reputation: 1

Kinect - Play & Pause music in Processing

I'm trying to play music when I move my hand forward and pause music when I move my hand background as in this video.

I can play music when I move forward. But I can't see how to pause my player when I move background.

import ddf.minim.*;
import SimpleOpenNI.*;

SimpleOpenNI kinect;

int closestValue;
int closestX;
int closestY;
PImage img;
AudioPlayer player;
Minim minim;

void setup() {
    size(640, 480);
    img = loadImage("background.jpg");
    kinect = new SimpleOpenNI(this);
    kinect.enableDepth();
    image(img, 0, 0);
    minim = new Minim(this);
    player = minim.loadFile("music.mp3");
    }

void draw() {
    closestValue = 600;
    kinect.update();

    int[] depthValues = kinect.depthMap();

    // this breaks our array down into rows  
    for (int y = 0; y < 480; y++ ) {  

        // this breaks our array down into specific pixels in each row  
        for (int x = 0; x < 640; x++) {  

            // this pulls out the specific array position  
            int i = x + y * 640;  
            int current = depthValues[i];  


            //now we're on to comparing them!  
            if ( current > 0 && current < closestValue) {  
                closestValue = current;  
                closestX = x;  
                closestY = y;
                player.play();
                }

            /// I made this else if in order to make the pause when the current value is superior or equal to the closest value ///
           /// but it doesn't play the player, it seems that it directly pauses the player. ///

            /*else if ( current > 0 && current >= closestValue) {
                player.pause();
                }*/
            }
       }

       // draw the depth image on the screen  
       image(kinect.depthImage(), 0, 0);  

      // draw that swanky red circle identifying it  
      fill(255, 0, 0); //This sets the colour to red  
      ellipse(closestX, closestY, 25, 25);
}

Upvotes: -1

Views: 228

Answers (1)

Juliyanage Silva
Juliyanage Silva

Reputation: 2699

Try to player.pause(); in the play code segment and see what happens. If it pauses. then it's because of the expression you are using for the else if statement.

Upvotes: 0

Related Questions