streamprogress.lzx
<library>
<class name="streamprogress">
<attribute name="maxwidth" value="${parent.width}" type="number"/>
<attribute name="width" value="0
"/>
<attribute name="height" value="10
"/>
<attribute name="stream" value="null
"/>
<attribute name="time" value="0
"/>
<attribute name="totaltime" value="0
"/>
<attribute name="progress" value="0
"/>
<attribute name="bgcolor" value="green
"/>
<event name="onstream"/>
<event name="ontime"/>
<event name="ontotaltime"/>
<event name="onprogress"/>
<attribute name="_timedel" value="null
"/>
<setter name="stream" args="newStream">
Debug.write('progress %w set stream %w', this, newStream);
this.stream = newStream;
if (!this._timedel) {
this._timedel = new LzDelegate(this, "_updateTime");
} else {
this._timedel_unregisterAll();
}
this._timedel.register(this.stream, "ontime");
this._timedel.register(this.stream, "ontotaltime");
if (this.onstream) this.onstream.sendEvent(this);
</setter>
<method name="_updateTime" args="ignore=null">
var newTime = false, newTotal = false;
if (this.time != this.stream.time) {
newTime = true;
this.time = this.stream.time;
}
if (this.totaltime != this.stream.totaltime) {
newTotal = true;
this.totaltime = this.stream.totaltime;
}
this.progress = this.totaltime > 0 ?
this.time / this.totaltime : 0;
this._updateWidth();
if (this.ontime && newTime) this.ontime.sendEvent(this);
if (this.ontotaltime && newTotal) this.ontotaltime.sendEvent(this);
if (this.onprogress) this.onprogress.sendEvent(this);
</method>
<method name="_updateWidth">
this.setAttribute('width',this.maxwidth * this.progress);
</method>
</class>
</library>