mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-21 00:59:29 +00:00
Handle updating seek sliders
This commit is contained in:
parent
9cda59c125
commit
87dc5d2a77
1 changed files with 35 additions and 2 deletions
|
|
@ -17,6 +17,7 @@ export default class Slider extends GuiObj {
|
|||
_high: number;
|
||||
_position: number = 0;
|
||||
_thumbDiv: HTMLDivElement = document.createElement("div");
|
||||
_actionSubscription: null | (() => void);
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
|
@ -102,8 +103,7 @@ export default class Slider extends GuiObj {
|
|||
this._high = num(value);
|
||||
break;
|
||||
case "action":
|
||||
// Undocumented on the Wiki
|
||||
this._action = value;
|
||||
this._setAction(value);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
|
@ -111,6 +111,34 @@ export default class Slider extends GuiObj {
|
|||
return true;
|
||||
}
|
||||
|
||||
_setAction(value: string) {
|
||||
if (this._actionSubscription != null) {
|
||||
this._actionSubscription();
|
||||
this._actionSubscription = null;
|
||||
}
|
||||
this._action = value.toLowerCase();
|
||||
switch (this._action) {
|
||||
case "seek": {
|
||||
const update = () => {
|
||||
this._position = UI_ROOT.audio.getCurrentTimePercent();
|
||||
// TODO: We could throttle this, or only render if the change is "significant"?
|
||||
this._renderThumbPosition();
|
||||
};
|
||||
update();
|
||||
this._actionSubscription = UI_ROOT.audio.onCurrentTimeChange(update);
|
||||
break;
|
||||
}
|
||||
case "eq_band":
|
||||
break;
|
||||
case "pan":
|
||||
break;
|
||||
case "volume":
|
||||
break;
|
||||
default:
|
||||
assume(false, `Unhandled slider action: ${this._action}`);
|
||||
}
|
||||
}
|
||||
|
||||
// extern Int Slider.getPosition();
|
||||
getposition(): number {
|
||||
return this._position * 255;
|
||||
|
|
@ -173,6 +201,11 @@ export default class Slider extends GuiObj {
|
|||
this._div.appendChild(this._thumbDiv);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
super.dispose();
|
||||
this._actionSubscription();
|
||||
}
|
||||
|
||||
/*
|
||||
extern Slider.onPostedPosition(int newpos);
|
||||
extern Slider.onSetFinalPosition(int pos);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue