Skip to content

Commit

Permalink
video-texture: Allow videos to play if muted
Browse files Browse the repository at this point in the history
Signed-off-by: Squareys <squareys@googlemail.com>
  • Loading branch information
Squareys committed Feb 25, 2025
1 parent 8222869 commit a959df3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions video-texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,22 @@ export class VideoTexture extends Component {
});

if (this.autoplay) {
window.addEventListener('click', this.playAfterUserGesture);
window.addEventListener('touchstart', this.playAfterUserGesture);
/* Muted videos are allowed to play immediately. Videos with sound
* need to await a user gesture. */
if (this.muted) {
this.video?.play();
} else {
window.addEventListener('click', this.playAfterUserGesture);
window.addEventListener('touchstart', this.playAfterUserGesture);
}
}
}

onDestroy() {
this.video?.remove();
this.texture?.destroy();

if (this.autoplay) {
if (this.autoplay && !this.muted) {
/* In case not removed yet, we remove the autoplay gestures here.
* If already removed, these have no effect. */
window.removeEventListener('click', this.playAfterUserGesture);
Expand Down

0 comments on commit a959df3

Please # to comment.