repo: janusweb
action: commit
revision: 
path_from: 
revision_from: dde0c0eaecf268b954eec19b9a6400190288dad3:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit dde0c0eaecf268b954eec19b9a6400190288dad3
Author: James Baicoianu 
Date:   Sat Jun 13 00:15:15 2020 -0700

    Handle audio autoplay for videos

diff --git a/scripts/video.js b/scripts/video.js
index d3a907cf1c75ca221e669b1dc8426308dc363bb4..
index ..879393843d8797d4868e280686b90c2753e3c0bb 100644
--- a/scripts/video.js
+++ b/scripts/video.js
@@ -97,6 +97,7 @@ elation.require(['janusweb.janusbase'], function() {

       this.soundobj = new THREE.PositionalAudio(listener);
       this.objects['3d'].add(this.soundobj);
+      this.soundobj.isPlaying = true;
       //this.panner = this.context.createPanner();

       //this.panner.connect(ctx.destination);
@@ -153,8 +154,16 @@ elation.require(['janusweb.janusbase'], function() {
       return (video && video.currentTime > 0 && !video.paused && !video.ended);
     }
     this.play = function() {
-      if (!this.isPlaying()) {
-        this.video.play();
+      if (!this.engine.systems.sound.canPlaySound) {
+        if (!this.playDelayed) {
+          this.playDelayed = true;
+          elation.events.add(this.engine.systems.sound, 'sound_enabled', (ev) => { this.play(); });
+          this.dispatchEvent({type: 'sound_delayed'});
+        }
+      } else {
+        if (!this.isPlaying()) {
+          this.video.play();
+        }
       }
     }
     this.pause = function() {

-----END OF PAGE-----