| 17 | private unsubPosition: () => void; |
| 18 | |
| 19 | constructor(api: alphaTab.AlphaTabApi) { |
| 20 | this.root = parseHtml(html` |
| 21 | <div class="at-time-slider-wrap"> |
| 22 | <div class="cmp-progress"></div> |
| 23 | </div> |
| 24 | `); |
| 25 | this.bar = mount(this.root, '.cmp-progress', new ProgressBar()); |
| 26 | this.bar.onClickPercent = percent => { |
| 27 | if (this.endTime > 0) { |
| 28 | api.timePosition = Math.floor(this.endTime * percent); |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | this.unsubMidiLoaded = api.midiLoaded.on(e => { |
| 33 | this.endTime = e.endTime; |
| 34 | }); |
| 35 | this.unsubPosition = api.playerPositionChanged.on(args => { |
| 36 | if (args.endTime > 0) { |
| 37 | this.bar.setValue(args.currentTime / args.endTime); |
| 38 | } |
| 39 | }); |
| 40 | } |
| 41 | |
| 42 | dispose(): void { |
| 43 | this.unsubMidiLoaded(); |