Skip to content

Commit

Permalink
stop mjpeg image loading and video playing when they are not visible
Browse files Browse the repository at this point in the history
closes #141
  • Loading branch information
peuter committed Apr 30, 2017
1 parent bb9f46f commit 11bb401
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
9 changes: 7 additions & 2 deletions source/class/cv/ui/structure/AbstractWidget.js
Expand Up @@ -18,7 +18,7 @@
*/


//noinspection JSUnusedGlobalSymbols
//noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols,JSHint
/**
* This class defines all the building blocks for a Visu in the "Pure" design
*/
Expand Down Expand Up @@ -91,7 +91,8 @@ qx.Class.define('cv.ui.structure.AbstractWidget', {
visible : {
check: "Boolean",
init: false,
event: "changeVisible"
event: "changeVisible",
apply: "_applyVisible"
}
},

Expand All @@ -112,6 +113,10 @@ qx.Class.define('cv.ui.structure.AbstractWidget', {
members: {
$$domReady: null,

// property apply
_applyVisible: function(value, old) {
},

/**
* Property transformaon helper
* @param value {String}
Expand Down
38 changes: 32 additions & 6 deletions source/class/cv/ui/structure/pure/Image.js
Expand Up @@ -53,6 +53,8 @@ qx.Class.define('cv.ui.structure.pure.Image', {
******************************************************
*/
members: {
__src: null,

// overridden
_getInnerDomString: function () {
// create the actor
Expand All @@ -66,13 +68,37 @@ qx.Class.define('cv.ui.structure.pure.Image', {
if (this.getHeight()) {
imgStyle += 'height:' + this.getHeight() + ';';
}
var src = this.getSrc();
var parsedUri = qx.util.Uri.parseUri(this.getSrc());
if (!parsedUri.protocol && !this.getSrc().startsWith("/")) {
// is relative URI, use the ResourceManager
src = qx.util.ResourceManager.getInstance().toUri(this.getSrc());
return '<div class="actor"><img src="' + this.__getSrc() + '" style="' + imgStyle + '" /></div>';
},

/**
* Return the real src value
*/
__getSrc: function() {
if (!this.__src) {
var src = this.getSrc();
var parsedUri = qx.util.Uri.parseUri(this.getSrc());
if (!parsedUri.protocol && !this.getSrc().startsWith("/")) {
// is relative URI, use the ResourceManager
src = qx.util.ResourceManager.getInstance().toUri(this.getSrc());
}
this.__src = src;
}
return this.__src;
},

// overridden
getValueElement: function() {
return qx.bom.Selector.query("img", this.getDomElement())[0];
},

// overridden
_applyVisible: function(value) {
if (value === true) {
qx.bom.element.Attribute.set(this.getValueElement(), "src", this.__getSrc());
} else {
qx.bom.element.Attribute.set(this.getValueElement(), "src", "");
}
return '<div class="actor"><img src="' + src + '" style="' + imgStyle + '" /></div>';
}
},

Expand Down
17 changes: 16 additions & 1 deletion source/class/cv/ui/structure/pure/Video.js
Expand Up @@ -56,8 +56,23 @@ qx.Class.define('cv.ui.structure.pure.Video', {
style += 'height:' + this.getHeight() + ';';
}
if (style !== '') { style = 'style="' + style + '"'; }
var autoplay = (this.getAutoplay() === true) ? ' autoplay="autoplay"' : '';
var autoplay = this.isAutoplay() ? ' autoplay="autoplay"' : '';
return '<div class="actor"><video src="' + this.getSrc() + '" ' + style + autoplay + ' controls="controls" /></div>';
},

// overridden
getValueElement: function() {
return qx.bom.Selector.query("video", this.getDomElement())[0];
},

// overridden
_applyVisible: function(value) {
var video = this.getValueElement();
if (value === true && this.isAutoplay()) {
video.play();
} else {
video.pause();
}
}
}
});

0 comments on commit 11bb401

Please sign in to comment.