[SOLVED] Play second video when first video ends?

this might seem trivial but, how do you make the video move to the next “scene” automatically after the video ends?

void draw() { 
    
  //----------game states-------------
  if (state == 0) // 0 welcome screen
  {
    welcomeScreen();
  } else if (state == 1) // 1 play the story state
  {
    story();
  } else if (state == 2) // 2 starts the tutorial screen
  {
    tutorial();
  } else if (state == 3) // 3 shows the kinect screen
  {
    kinect();
  } else if (state == 4) // 4 shows the win screen
  {
    winScreen();
  }
  else if (state == 5){ // 5 shows the loose screen
    looseScreen(); 
} else {
  state = 0;
 }
}  

// for example, after storyscene video ends, play tutorial video
void story() {
   println("storyscene");
   startVid.stop();
   lostGame.stop();
   WinGame.stop();
   background(0);
   storyscene.play();
   image(storyscene, 0, 0, width, height);

void tutorial() {
   println("tutorialscene");
   startVid.stop();
   storyscene.stop();
   lostGame.stop();
   WinGame.stop();
   background(0);
   tutorialscene.play();
   image(tutorialscene, 0, 0, width, height);

    countDownTimer.start();
}

}

I am trying out using this but does not work

   if (storyscene.time() == storyscene.duration()) {
        state = 2;

You can try with:

if (storyscene.duration() - storyscene.time() == 0) {
  state = 2
}
1 Like

or better not use == on float numbers, try <= …

2 Likes

This is with Processing Video I assume …?

For some reason, that doesn’t give access to the obvious playing state or EOS signal! However, for some other unknown reason it looks like the actual PlayBin is public. :confounded: That doesn’t make a lot of sense, but it is useful - you should be able to use something like (not tested!) -

if (!storyscene.playbin.isPlaying()) {
  // handle state change
}

@kesson be a little wary of using duration() and time() for anything, and definitely don’t use ==.

1 Like

Because overriding an existing method and giving it different semantics is the way to do this??? :roll_eyes:

ok with some slight modification to the code, actually its quite basic and just 1 line of code. Seems to work

 if (tutorialscene.time() >= 5.32) {
 state = 3;

}

I used println(tutorialscene.time()); to get the exact duration of the video so that when it reaches 5.32 secs it switches to the next video “state”

2 Likes

Method Movie::hasBufferSink() isn’t invoked anywhere within the whole library. :film_projector:

And quite frankly, I’ve never seen any1 call this method and neither can’t see any need for it! :face_with_hand_over_mouth:

Therefore, as long as field playing isn’t public, or at least until the library give us a getter for that field, re-purposing a totally useless public method is the easiest workaround to go! :triumph:

And an even better workaround: @Override Movie::eosEvent() method as public: :yum:


Actually the easiest (and safest) thing should be what I posted above!

For your workaround you had to search for the API of the GStreamer’s class PlayBin2.

And for mine, I had to search within the Movie library itself.

In both cases, it’s not trivial for a regular Processing user to pull those out by themselves!

Clearly, the Movie library has a very poor API, lacking other very important methods for a comfortable usage!

Well, I didn’t! On the basis that I have maintained this code for years. I’m just saying that accessing the PlayBin API this way is safer than the other options above. I agree that the Movie API needs improving to expose this stuff. There’s an active GSoC project working on the library at the moment. Maybe suggest what’s missing?

For starters, make the 3 boolean fields below public:

Knowing when a Movie has ended streaming is an eternal recurrent request.

An extra eosEvent() callback in addition to movieEvent() would make the library much easier to use.

As in, file GitHub issues for these! :wink: No idea if anyone working on it will see it here.

Like this 1 from 2015? :sleeping:

Fair enough! Added a comment on the issue. The other thing that’s missing in the Video library, although can be done with the PlayBin reference, is being able to set the file. This can all be done in GStreamer with one PlayBin, including seamless switching.

1 Like

…and it was merged on GitHub!