We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi,
so im quite a noob, just clearing that.
im working on a project which involves switching between multiple videos on processing when i press a key. im trying to do some initial testing right now, and trying to get processing to switch between two videos on keypress. the video switches alright, but i cant see it in the applet window! the previous video ( in the paused state continues to stay on top ) . how do i fix this?? please help. find the code below -
import processing.video.*;
Movie theMov;
Movie theMov2;
void setup() {
size(1440, 900);
theMov = new Movie(this, "sin_city.mp4");
theMov2 = new Movie(this, "blue_velvet.mp4");
theMov.stop();
theMov2.stop();
}
void draw() {
background (0);
image(theMov, 0, 0);
image(theMov2, 0, 0);
}
void movieEvent(Movie m) {
m.read();
}
void keyPressed(){
if (key == 'p'){
theMov2.pause();
background(0);
theMov.play();
} else if (key == 'o'){
theMov.pause();
background(0);
theMov2.play();
}
}
Answers
You're always displaying both theMov & theMov2:
Since it's just 2 Movie streams, you can declare a
boolean
variable to determine which 1 is active for image():But if you've got more, you're gonna need a Movie[] array. Plus a variable to keep track of its current index:
ok so ultimately im gonna need to toggle between 4 movies. if its not much trouble could you elaborate on the Movie[] array a little? like how do i call the desired movie to play on keyPress. ( sorry if this is a really silly question :P)
Something akin to these lines: ~O)
More about arrays: =:)
cancelled this comment since it was useless :)
o sorry! didnt see your new comment. let me try it out!
hell yea!
it worked! thanks so much GoToLoop!
so i understand bits of what you have done there, but say i want to use very specific keys, lets say 'a' 's' 'd' to trigger off the videos, then how do i go about doing that?? Some help would be greatly appreciated!
There are couple of strategies for it. For example,
switch/case
associating keyCode w/ a returning index: *-:)P.S.: getMovieIndex() is only necessary if indices associated to a keyCode is arbitrary.
If it happens to be in alphabetical order, the same trick from my 1st example can be used. Just replace '1' w/ 'A'!
yep! it worked! im just having one issue. when i load the java applet, its obviously a blank black screen which is fine. however, when i click on 'a' nothing happens. But when i click on 's' or 'd' for that matter it works, after which if i press 'a' then that also works. Could it be because the system has considered the default movie[idx] as '0', because of which, when i click 'a' for the first time it does nothing? if thats the case, or whatever else the case, whats the work around? im attaching my entire code for you to see in case i have goofed up somewhere. thanks a ton! :)
ok so i just made a small change and it seems to be working perfect now! is this a good way to tackle this? -
if (n >= 0 ){ //& n!= idx) { movies[idx].pause(); movies[idx = n].loop(); }
That "bug" happens b/c no Movie plays at the beginning. And since
idx = 0
, it's wrongly assumedmovies[0]
is active! My propose is includemovies[0].loop()
within setup() rather than remove& n!=idx
: o=>P.S.:
& n!=idx
is there to avoid unnecessary pause() & play() for the same active idx. Just a tiny optimization! ;)Here's a tweaked version which relies on noLoop()/redraw() combo, so canvas updates only when movieEvent() happens. I expect it to be lighter this way. ~:> Also included pause/rewind/forward features! <:-P
thanks so much GoToLoop! obviously both the codes are working. Ok so let me fill you in on the bigger picture. im doing all of this for a art festival called Story of Light. And one of the exhibits is going to be a television ( well at least we are going to make it seem like a television). there will be different colored stools in front of the TV. when a user comes and sits on lets say, the red chair, the surrounding light is going to change color to a red light & after maybe a 2 second delay the TV will switch on, showing some news videos footage that sort of matches the mood of that particular light color. So when the first user walks in, i need the tv screen to be blank, in which case, 'movies[idx].loop' wont work for me. Any workaround that? Also thanks so much for the pause and forwarding features! really! but wont really be needing them :D
also any ideas on how im finally gonna be interfacing this video toggling using analog sensors on the arduino?
also regarding the second code that you sent me, the first time i fire up the applet, the video plays off the centre of the applet, towards the right bottom edge. However after toggling around, when i return to it, it plays in the centre..
@GoToLoop Thank you very much!! over the last two weeks I have poured over many forum posts reading over your contributions in an effort to write a small program that interfaces with the kinect and allows me to using the depth image as a mask. I have basically completed it, with a few issues that I can't seem to resolve, but they are minor ...anyway, thanks!