Browse Source

Merge pull request #9040 from simonihmig/muted-video

Add muted setting to VideoTexture, fix autoplay in Chrome
David Catuhe 4 năm trước cách đây
mục cha
commit
78d2fc1ca3
2 tập tin đã thay đổi với 13 bổ sung1 xóa
  1. 1 0
      dist/preview release/what's new.md
  2. 12 1
      src/Materials/Textures/videoTexture.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -166,6 +166,7 @@
 - Added the possibility to update the shader code before being compiled ([Popov72](https://github.com/Popov72))
 - Added the `shadowOnly` property to the `BackgroundMaterial` class ([Popov72](https://github.com/Popov72))
 - Added support for lightmaps in unlit PBR materials ([Popov72](https://github.com/Popov72))
+- Added `muted` setting to `VideoTexture`, fix autoplay in Chrome ([simonihmig](https://github.com/simonihmig))
 
 ### Meshes
 

+ 12 - 1
src/Materials/Textures/videoTexture.ts

@@ -18,6 +18,11 @@ export interface VideoTextureSettings {
     autoPlay?: boolean;
 
     /**
+     * Applies `muted` to video, if specified
+     */
+    muted?: boolean;
+
+    /**
      * Applies `loop` to video, if specified
      */
     loop?: boolean;
@@ -110,13 +115,15 @@ export class VideoTexture extends Texture {
         if (settings.poster) {
             this.video.poster = settings.poster;
         }
-
         if (settings.autoPlay !== undefined) {
             this.video.autoplay = settings.autoPlay;
         }
         if (settings.loop !== undefined) {
             this.video.loop = settings.loop;
         }
+        if (settings.muted !== undefined) {
+            this.video.muted = settings.muted;
+        }
 
         this.video.setAttribute("playsinline", "");
 
@@ -126,6 +133,10 @@ export class VideoTexture extends Texture {
         this._createInternalTextureOnEvent = (settings.poster && !settings.autoPlay) ? "play" : "canplay";
         this.video.addEventListener(this._createInternalTextureOnEvent, this._createInternalTexture);
 
+        if (settings.autoPlay) {
+            this.video.play();
+        }
+
         const videoHasEnoughData = (this.video.readyState >= this.video.HAVE_CURRENT_DATA);
         if (settings.poster &&
             (!settings.autoPlay || !videoHasEnoughData)) {