Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

myVideo variable contains a Null but how to solve this?

$
0
0
This are my first steps in Programming and Processing and I wanted to several videos based on several sensor values from an arduino. However the variable myVideo gives a null and Java is not happy with that and so am I. The strange thing is that after some tries it suddenly does work. Anyone having a clue how this might be? 

  1. /* 
  2.  * Sketch to start playing the right videofile when a certain sensor value is communicated (processing code)
  3.  */

  4. import processing.serial.*; //two libraries are added, one for the serial communication and the other one to play the movie files.
  5. import processing.video.*;
  6. Movie myMovie;
  7. Serial port;  
  8. int pageValue;  //This variable is later used to store the data input from the arduino

  9. void setup() {
  10.   size(800, 480, P3D);//800x480 is the resolution of the video files, this is allready pretty sluggish and the                                     intention was to play it on a 4" screen therefore the resolution is not higher. 
  11.   noStroke();        //P3D is added to the setup so the videofile starts playing actually, otherwise processing will just crash. 
  12.   port = new Serial(this, Serial.list()[0], 9600);
  13. }

  14. void draw() {
  15.         if (0 < port.available()) {   //Check to see if there is actually data for me available 
  16.                 pageValue = port.read();  // Here I store the information from the datacommunication in the                                                             variable pageValue
  17.                 pageCheck(); //Here the function pageCheck is called which starts to play videofiles determined                                           on which page you are.
  18.         }
  19.   background(204);         
  20.   println(pageValue);        //Check to see what values the variable pageValue holds, another check to see                                           how the communication is going and where an error occurs.
  21.   println(myMovie);
  22.   image(myMovie, 0, 0);
  23. }

  24. void movieEvent(Movie myMovie) {
  25.   myMovie.read();
  26. }


  27. boolean played1 = false;
  28. boolean played2 = false;
  29. boolean played3 = false;
  30. boolean played4 = false;
  31. boolean played5 = false;
  32. boolean played6 = false;
  33. boolean played7 = false;
  34. boolean played8 = false;

  35. void pageCheck() { //This function checks which value the variable pageValue is and then selects the right videofile for that and then starts playing that file. I could have done this in an array but because of all the troubles I did not manage to make this in time. 
  36.   if (pageValue == 1 && played1 == false) {
  37.     played1 = true;
  38.     myMovie = new Movie(this, "pagina 5.mp4");
  39.     myMovie.play();
  40.     image(myMovie, 0, 0);
  41. }
  42.   if (pageValue == 2 && played2 == false) {
  43.     played2 = true;
  44.     myMovie = new Movie(this, "pagina 7.mp4");
  45.     myMovie.play();
  46.     image(myMovie, 0, 0);
  47.   }
  48.   if (pageValue == 3 && played3 == false) {
  49.     played3 = true;
  50.     myMovie = new Movie(this, "pagina 9.mp4");
  51.     myMovie.play();
  52.     image(myMovie, 0, 0);
  53.   }
  54.   if (pageValue == 4 && played4 == false) {
  55.     played4 = true;
  56.     myMovie = new Movie(this, "pagina 11.mp4");
  57.     myMovie.play();
  58.     image(myMovie, 0, 0);
  59.   }
  60.   if (pageValue == 5 && played5 == false) {
  61.     played5 = true;
  62.     myMovie = new Movie(this, "pagina 13.mp4");
  63.     myMovie.play();
  64.     image(myMovie, 0, 0);
  65.   }
  66.   if (pageValue == 6 && played6 == false) {
  67.     played6 = true;
  68.     myMovie = new Movie(this, "pagina 15.mp4");
  69.     myMovie.play();
  70.     image(myMovie, 0, 0);
  71.   }
  72.   if (pageValue == 7 && played7 == false) {
  73.     played7 = true;
  74.     myMovie = new Movie(this, "pagina 17.mp4");
  75.     myMovie.play();
  76.     image(myMovie, 0, 0);
  77.   }
  78.   if (pageValue == 8 && played8 == false) {
  79.     played8 = true;
  80.     myMovie = new Movie(this, "pagina 19.mp4");
  81.     myMovie.play();
  82.     image(myMovie, 0, 0);
  83.   }
The arduino code sends 1,2,3,4,5,6,7 or 8 through the serial port continuously. 

Viewing all articles
Browse latest Browse all 1768

Trending Articles