From 94bcd87a9fde270c413d4cd25877c771731b5c21 Mon Sep 17 00:00:00 2001 From: AlexandreS <32449369+AlexandreSi@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:15:10 +0200 Subject: [PATCH] Add stop method on video and use it when object is destroyed (#5833) Fixes bug where video are not restarted when switching scenes --- .../Video/videoruntimeobject-pixi-renderer.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Extensions/Video/videoruntimeobject-pixi-renderer.ts b/Extensions/Video/videoruntimeobject-pixi-renderer.ts index 76a9f9366ce7..0d899e9a12bd 100644 --- a/Extensions/Video/videoruntimeobject-pixi-renderer.ts +++ b/Extensions/Video/videoruntimeobject-pixi-renderer.ts @@ -49,10 +49,11 @@ namespace gdjs { } /** - * To be called when the object is removed from the scene: will pause the video. + * To be called when the object is removed from the scene: will stop the video + * (goes back to beginning). */ onDestroy() { - this.pause(); + this.stop(); } ensureUpToDate() { @@ -172,6 +173,18 @@ namespace gdjs { source.pause(); } + /** + * Stops the video and comes back to first frame. + */ + stop() { + const source = this._getHTMLVideoElementSource(); + if (!source) { + return; + } + source.pause(); + source.currentTime = 0; + } + // Autoplay was prevented. /** * Set the loop on video in renderer