Skip to content

Commit

Permalink
Add cleanup watchdog for fast-skipping of video
Browse files Browse the repository at this point in the history
  • Loading branch information
MrApplejuice committed Sep 16, 2023
1 parent 2f11574 commit 9adfa28
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions web/pixi_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,31 @@ def _instvid__start_clicked(self):
self.pixi.stage.removeChild(self._instvid__play_container)
self._instvid__video = PIXI.Texture.js_from(VIDEO_URL)

self._instvid__video_sprite = do_new(
video_sprite = self._instvid__video_sprite = do_new(
PIXI.Sprite,
self._instvid__video,
{}
)
video_source = video_sprite.texture.baseTexture.resource.source

self._instvid__video_sprite.width = 800
self._instvid__video_sprite.height = 800 / 16 * 9
self._instvid__video_sprite.anchor = pixipt(0.5, 0.5)
self._instvid__video_sprite.position = pixipt(400, 300)

self.pixi.stage.addChild(self._instvid__video_sprite)

self._instvid__video_sprite.texture.baseTexture.resource.source.addEventListener(
# When playback start is delayed a _lot_ we might still need to clean things
# up because someone clicked "skip" before playback even started

def watchdog_cleanup():
if self._instvid__video_sprite is None:
window.clearInterval(interval_id)
video_source.pause()

interval_id = window.setInterval(watchdog_cleanup, 100)

video_source.addEventListener(
"ended", self._instvid__cleanup
)
self.pixi.stage.addChild(self._instvid__skip_container)
Expand Down

0 comments on commit 9adfa28

Please sign in to comment.