2015-11-24 13 views
-1

Я пытаюсь играть музыку, когда я двигаю рукой вперед и останавливаю музыку, когда я двигаю своим фоном, как в этом video.Kinect - Воспроизведение и пауза в обработке

Я могу играть музыку, когда я продвигаюсь вперед. Но я не могу понять, как приостановить мой плеер, когда я перемещаю фон.

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); 
} 

ответ

0

Попробуйте плеера.pause(); в сегменте игрового кода и посмотреть, что произойдет. Если он приостанавливается. то это из-за выражения, которое вы используете для инструкции else if.