# \[SOLVED\] Play second video when first video ends?

**URL:** https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512
**Category:** Libraries
**Created:** [August 21, 2019, 5:17am UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512 "2019-08-21T05:17:34Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![AxeFire](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@AxeFire](https://discourse.processing.org/u/AxeFire)
#### Post date: [August 21, 2019, 5:17am UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/1 "2019-08-21T05:17:34Z")

</div>

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

```auto
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

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

```

---

<div class="post-metadata">

### Author: ![kesson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kesson/32/2286_2.png) [@kesson](https://discourse.processing.org/u/kesson)
#### Post date: [August 21, 2019, 9:18am UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/2 "2019-08-21T09:18:31Z")

</div>

You can try with:

```auto
if (storyscene.duration() - storyscene.time() == 0) {
  state = 2
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [August 21, 2019, 9:25am UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/3 "2019-08-21T09:25:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [August 21, 2019, 11:12am UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/4 "2019-08-21T11:12:15Z")

</div>

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. 😖 That doesn’t make a lot of sense, but it is useful - you should be able to use something like (not tested!) -

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

```

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

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [August 21, 2019, 11:20am UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/5 "2019-08-21T11:20:31Z")

</div>

> [@AxeFire](#):
>
> … after the video ends?

> [@Help with text and video](https://discourse.processing.org/t/help-with-text-and-video/2104/9):
>
> /\*\* \* Hacked Movie isPlaying() (v1.0) \* GoToLoop (2018/Jul/28) \* Discourse.Processing.org/t/help-with-text-and-video/2104/9 \*/ import processing.video.Movie; Movie vid; void setup() { frameRate(30); textSize(050); textAlign(CENTER, BASELINE); fill(#FFFF00); vid = new Movie(this, "transit.mov") { @Override public boolean hasBufferSink() { return playing; } }; vid.play(); while (vid.width == 0 | vid.height == 0) delay(10); getSurface().setSize(vid.width, v…

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [August 21, 2019, 11:43am UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/6 "2019-08-21T11:43:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![AxeFire](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@AxeFire](https://discourse.processing.org/u/AxeFire)
#### Post date: [August 21, 2019, 11:44am UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/7 "2019-08-21T11:44:48Z")

</div>

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”

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [August 21, 2019, 5:19pm UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/8 "2019-08-21T17:19:23Z")

</div>

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

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

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! 😤

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [August 21, 2019, 5:42pm UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/9 "2019-08-21T17:42:06Z")

</div>

And an even better workaround: `@Override` Movie::**eosEvent()** method as `public`: 😋

- [Forum.Processing.org/two/discussion/14990/movie-begin-and-end-events#Item\_1](http://Forum.Processing.org/two/discussion/14990/movie-begin-and-end-events#Item_1)

> <https://github.com/processing/processing-video/blob/2/src/processing/video/Movie.java#L784-L790>

  

> <https://github.com/processing/processing-video/blob/2/src/processing/video/Movie.java#L854-L871>

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [August 21, 2019, 5:51pm UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/10 "2019-08-21T17:51:02Z")

</div>

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

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [August 21, 2019, 6:02pm UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/11 "2019-08-21T18:02:54Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [August 21, 2019, 6:28pm UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/12 "2019-08-21T18:28:39Z")

</div>

> [@GoToLoop](#):
>
> For your workaround you had to search for the API of the GStreamer’s class

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?

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [August 21, 2019, 6:41pm UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/13 "2019-08-21T18:41:54Z")

</div>

> [@neilcsmith](#):
>
> Maybe suggest what’s missing?

For starters, make the 3 `boolean` fields below `public`:

> <https://github.com/processing/processing-video/blob/2/src/processing/video/Movie.java#L59-L61>

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.

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [August 21, 2019, 6:53pm UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/14 "2019-08-21T18:53:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [August 21, 2019, 6:58pm UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/15 "2019-08-21T18:58:18Z")

</div>

> [@neilcsmith](#):
>
> As in, file GitHub issues for these!

Like this 1 from 2015? 😴

> <https://github.com/processing/processing-video/pull/29>
>
> Would be great, if you can add these getters for the next processing release.

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [August 21, 2019, 9:56pm UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/16 "2019-08-21T21:56:30Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [August 22, 2019, 4:05pm UTC](https://discourse.processing.org/t/solved-play-second-video-when-first-video-ends/13512/17 "2019-08-22T16:05:30Z")

</div>

…and it was merged on GitHub!
