Skip to content

Commit

Permalink
Add stop method on video and use it when object is destroyed (#5833)
Browse files Browse the repository at this point in the history
Fixes bug where video are not restarted when switching scenes
  • Loading branch information
AlexandreSi authored Oct 25, 2023
1 parent 356a197 commit 94bcd87
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Extensions/Video/videoruntimeobject-pixi-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 94bcd87

Please sign in to comment.