#Video Reset Question

1 messages · Page 1 of 1 (latest)

warm thicket
#

Hi all... it's entirely possible that I'm massively overthinking this. I've been trying a tonne of stuff that's probably way more complicated than is necessary (and none of which has worked anyway 🙃 ) so am shouting out here to ask if there's a way to do the following.

I have a video in my unity scene that plays via a Playable Director (which is started by the user clicking a button). I'm trying to find a way to 'reset' the video when it's finished playing, so that instead of either 'holding' or 'looping' it simply goes back to its beginning and stops, to await being restarted (if required) by the user repeating the button interaction.

Any advice will be gratefully received, as always 🥰 ... the struggle is real (video reel 🤣 )

fickle brambleBOT
fickle brambleBOT
fickle brambleBOT
# warm thicket Hi all... it's entirely possible that I'm *massively* overthinking this. I've be...

Hi Frannie, it seems you want to reset a video controlled by a Playable Director in Needle Engine after it finishes playing. Based on the Needle Engine types documentation, the PlayableDirector class provides play(), pause(), and stop() methods that you can utilize to control the playback of the timeline (see the documentation).

To reset the video when it finishes, you would typically add an event listener or a callback that is triggered when the video ends. In Needle Engine, you might have to manually check if the video has ended by comparing the current timeline time with the duration and then call the stop() method, which presumably resets the timeline for you. After calling stop(), you can set the time property of PlayableDirector back to 0 to ensure it's at the beginning. Here's a simplified version of the code you may want to include in your component:

class YourCustomDirectorBehaviour extends Behaviour {
  private playableDirector: PlayableDirector;

  // Other methods and logic...

  update() {
    if (this.playableDirector && this.playableDirector.isPlaying && 
        this.playableDirector.time >= this.playableDirector.duration) {
      this.playableDirector.stop();
      this.playableDirector.time = 0; // Reset timeline to start
    }
  }

  // Event handler when user clicks a button
  onUserClick() {
    // As an example, assuming the PlayableDirector is assigned to this component
    this.playableDirector.play();
  }
}

thread_mtRmiSKhlPPySnfdmqhkeAGo

fickle brambleBOT
# warm thicket Hi all... it's entirely possible that I'm *massively* overthinking this. I've be...

Attach this custom behaviour to an object in your scene. Ensure that you reference and assign the PlayableDirector to playableDirector property in your custom behavior component. Also, make sure to hook up the onUserClick method to your button interaction logic. This is just a direction, and depending on how Needle Engine handles the specifics, you might have to adjust the update method to properly detect the video's end and reset it.

1 messages left GPT 4
thread_mtRmiSKhlPPySnfdmqhkeAGo

warm thicket
#

Thanks @fickle bramble , I'll give that a go 🙂

fickle brambleBOT
warm thicket
#

@fickle bramble, sadly this didn't work for me, as it doesn't specifically target the video.

After it's played I need the video to go back to the beginning and stop, so that it can be played again (in entirety) whenever the user wants to view it.

So, I'm still trying different things in the hope of finding a way forward 😊

iron vortex
#

Hi @warm thicket why are you playing the video via the PlayableDirector? Are you using our custom timeline track for this?

warm thicket
#

Hi @iron vortex 👋🙂

Good question re: PlayableDirector use!!! I did say that I was probably overthinking all this 🤣

On reflection, I think I can probably achieve what I want using ‘Play Animation on Click’. I’m off to give that a try right now. I’ll shout up here with news of success or failure 😊

iron vortex
#

Have you tried adding a button component to your object and from the button first call video.stop() and then add another event (2nd) to call video.play() ?

warm thicket
#

I haven't! I'll give that a try, too! Thanks for the tip! 🥰