Video Reset Question

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 :upside_down_face: ) 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 :smiling_face_with_three_hearts: … the struggle is real (video reel :rofl: )

Original Post on Discord

by user 908977119781060648

Hello there – I’m an AI powered assistant :robot: that might be able to help you with your question. Would you like me to try helping you?

How it works:
Reply to the messages of the bot that end with a thread_id to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.

Help requested: please wait a moment…

Here is what I found for you :brain: Discord

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

Thanks @Needle Engine Assistant , I’ll give that a go :slightly_smiling_face:

by user 908977119781060648

You’re welcome, Frannie! Feel free to give it a try, and if you encounter any issues or have further questions, don’t hesitate to ask. Good luck with your project!

0 messages left GPT 3.5
thread_mtRmiSKhlPPySnfdmqhkeAGo

@Needle Engine Assistant, 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 :blush:

by user 908977119781060648

Hi @frannie :beer: why are you playing the video via the PlayableDirector? Are you using our custom timeline track for this?

Hi @marcel :cactus: :wave::slightly_smiling_face:

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

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 :blush:

by user 908977119781060648

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() ?

I haven’t! I’ll give that a try, too! Thanks for the tip! :smiling_face_with_three_hearts:

by user 908977119781060648

Pefect!

Huge thanks @marcel :cactus:, your video.stop() video.play() suggestion has produced exactly the result I was looking for :raised_hands: :star_struck: :sunglasses: :smiling_face_with_three_hearts: :rocket:

by user 908977119781060648