repo: janusweb
action: commit
revision: 
path_from: 
revision_from: 5e09fc86ac4c6b033ef2e341d18dade8c76984dd:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit 5e09fc86ac4c6b033ef2e341d18dade8c76984dd
Author: James Baicoianu 
Date:   Sat Jan 14 19:52:10 2017 -0800

    Optimize video asset handling, respect auto_play parameter

diff --git a/scripts/object.js b/scripts/object.js
index f92e4b2b65a65e6768aa9aee270f2b310b7d3b3b..
index ..14f032f3e38f91f614e549525611d7813c5e6cc9 100644
--- a/scripts/object.js
+++ b/scripts/object.js
@@ -39,6 +39,9 @@ elation.require(['janusweb.janusbase', 'janusweb.websurface'], function() {
         this.pickable = false;
         this.collidable = false;
       }
+      if (this.video_id) {
+        elation.events.add(this, 'click', elation.bind(this, this.pauseVideo));
+      }
     }
     this.createObject3D = function() {
       if (this.properties.exists === false) return;
@@ -197,6 +200,7 @@ elation.require(['janusweb.janusbase', 'janusweb.websurface'], function() {
       if (this.properties.video_id) {
         var videoasset = this.getAsset('video', this.properties.video_id);
         if (videoasset) {
+          this.videoasset = videoasset;
           texture = videoasset.getInstance();
           if (videoasset.sbs3d) {
             texture.repeat.x = 0.5;
@@ -204,14 +208,15 @@ elation.require(['janusweb.janusbase', 'janusweb.websurface'], function() {
           if (videoasset.loop || this.properties.loop) {
             texture.image.loop = true;
           }
-          if (videoasset.auto_play) {
-            texture.image.play();
-          }
           texture.minFilter = THREE.LinearFilter;
           texture.magFilter = THREE.LinearFilter;
           elation.events.add(texture, 'videoframe', elation.bind(this, this.refresh));
-          elation.events.add(this, 'click', elation.bind(this, this.pauseVideo));
           this.videotexture = texture;
+          if (videoasset.auto_play) {
+            texture.image.play();
+          } else {
+            texture.image.pause();
+          }
         }
       }
       if (this.properties.websurface_id) {
@@ -364,10 +369,12 @@ elation.require(['janusweb.janusbase', 'janusweb.websurface'], function() {
         }
       }
       if (this.video_id) {
-        var texture = elation.engine.assets.find('video', this.video_id);
-        if (!texture.image.playing) {
-          texture.image.play();
-          //console.log('start the video!', texture);
+        if (this.videoasset && this.videotexture) {
+          var texture = this.videotexture;
+          if (!texture.image.playing && this.videoasset.auto_start) {
+            texture.image.play();
+            //console.log('start the video!', texture);
+          }
         }
       }
       if (this.websurface_id) {

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