how do i trigger video without it freezing?

Hey guys, i am currently working on a project where i need to read a database once to store a specific word in a variable, trigger a video to play and then repeat. However i can load the database in and pick out that specific word but when i get to the triggering it is like it plays one frame of the video and then freezes until the next repeat, I can't seem to solve this and some help would be great. Ill post my code below.

import processing.video.*;
Movie joyMov, sadnessmMov, angerMov, fearMov, analyticalMov, confidentMov, tentativeMov;
JSONArray values;

String mLab = "";

String Joy = "Joy";
String Fear = "Fear";
String Anger = "Anger";
String Sadness = "Sadness";
String Analytical = "Analytical";
String Confident = "Confident";
String Tentative = "Tentative";
String tone1;

void setup() {
  size(640, 360);
  //fullScreen();
  //surface.setResizable(true);
  background(0);
  frameRate(30);
  joyMov = new Movie(this, "joy.mp4");
  sadnessmMov = new Movie(this, "");
  angerMov = new Movie(this, "");
  fearMov = new Movie(this, "");
  analyticalMov = new Movie(this, "");
  confidentMov = new Movie(this, "");
  tentativeMov = new Movie(this, "");
  joyMov.loop();
}

void draw() {

  float count = frameCount % 150;
  if (count == 0) { 
   readDB();
   println(tone1);
   if(tone1.equals(Joy) == true) {
     println("the tone is: Joy");
     playJoyMov();
   } else if(tone1.equals(Anger) == true) {
     println("the tone is: Anger");
   } else if(tone1.equals(Sadness) == true) {
     println("the tone is: Sadness");
   } else if(tone1.equals(Fear) == true) {
     println("the tone is: Fear");
   } else if(tone1.equals(Analytical) == true) {
     println("the tone is: Analytical");
   } else if(tone1.equals(Confident) == true) {
     println("the tone is: Confident");
   } else if(tone1.equals(Tentative) == true) {
     println("the tone is: Tentative");
   }
  }
}

void readDB(){
  //load json from mlabs db
  values = loadJSONArray(mLab);
      //println(values[values.size()]);

  //for (int i = 0; i < values.size(); i++) {

    JSONObject tweet = values.getJSONObject(values.size()-1);
    println(tweet);

    //String location = tweet.getString("location");
    //String text = tweet.getString("tweet");
    //tone = tweet.values.getString("tone");
    tone1 = tweet.getString("tone");
    //println(location + " | " + text + " | " + tone);

  //}
}

void movieEvent(Movie m) {
  m.read();
}

void playJoyMov() {
  image(joyMov, 0, 0, width, height);
}

Answers

  • You are only updating anything every 150 frames, and only then if the json is correct, which it isn't, mlab is empty.

  • Introduce a current video global. Display the current frame from the current movie in every draw loop.

    Your 150th frame checking should be changed to decide which video is current.

Sign In or Register to comment.