M21Code / ProcessingVideo / selectVideo.pde
selectVideo.pde
Raw
void movieEvent(Movie m) {
  m.read();
}

void playOne(int idx) {
  mov[idx].play();
  //playlistSound[idx].rewind(); //Should be a nice function but creates a disturbed audio output on the vibration device
  if (vibroMode == 1) {
    playlistSound[idx].play();
  } else if (vibroMode == 2) {
    playlistHighFreq[idx].play();
  } else if (vibroMode == 3) {
    playlistLowFreq[idx].play();
  }
  duration = mov[idx].duration()*1000; //duration translated from seconds to milliseconds is *1000
  //println("Duration is" + mov[idx].duration()*1000);
  //println("The millis are" + int(millis()));

  //if (millis() > lastUpdate + 500) {
  // saveTemps();
  // lastUpdate = millis();
  //}
}

void stopOne(int idx) {
  //Set temp variable back to 0 for Arduino
  myPort.write('0');
  //Stop all video and vibro files from playing
  mov[idx].stop();
  playlistSound[idx].close();
  playlistHighFreq[idx].close();
  playlistLowFreq[idx].close();
  println("The video has ended");
  background (0);
  //Show the questions on screen and remove the items from this trial from the lists
  showQuestions();
  Inventories[pNum].remove(0);
  Orders[pNum].remove(0);
  Temps[pNum].remove(0);
  shownVideo = chosenVideo; //pure purpose for saving the correct video number to table
  chosenVideo = NOMOVIE;
  nextVideo();
}

void nextVideo() {
  if (Inventories[pNum].size() > 0) {
    image(playButton, width/2, (height/2)+100, 400, 400);
  } else if (Inventories[pNum].size() == 0) {
    textAlign(CENTER);
    textSize(50);
    text("This was the last video, click here to exit", width/2, (height/2)+400);
    if (mouseY > (height/2)+300 && mousePressed == true) {
      saveAnswers();
      exit();
    }
  }

  if (mouseX > (width/2)-200 && mouseX < (width/2)+200 && mouseY > (height/2)-100 && mouseY < (height/2)+300 && mousePressed == true) {
    if (Inventories[pNum].size() < 12) {
      saveAnswers();
      hideQuestions();
    }
    chosenVideo = Inventories[pNum].get(0);
    vibroMode = Orders[pNum].get(0);
    temp = Temps[pNum].get(0);
    println("pNum: " + pNum);
    println("Video: " + chosenVideo);
    println("vibroMode: " + vibroMode);
    println("temperature: " + temp);
    if (temp == 0) {
      myPort.write('0');
    } else if (temp == 20) {
      myPort.write('1');
    } else if (temp == 30) {
      myPort.write('2');
    } else if (temp == 40) {
      myPort.write('3');
    }
    startMillis = millis();
  }
}