| 91 | } |
| 92 | |
| 93 | private _load(): void { |
| 94 | this._error = null |
| 95 | this._loading = true |
| 96 | |
| 97 | this._term.reset() |
| 98 | this._timer.dispose() |
| 99 | this._queue.dispose() |
| 100 | this._timer = new NullTimer() |
| 101 | this._queue = new NullFrameQueue() |
| 102 | |
| 103 | this._onLoading.fire() |
| 104 | this._onStateChanged.fire(this.state) |
| 105 | |
| 106 | fetchCast(this._url).then((cast) => { |
| 107 | this._term.resize(cast.header.width, cast.header.height) |
| 108 | |
| 109 | if (cast.header.audio) { |
| 110 | this._timer = new MediaTimer(this._audio) |
| 111 | this._audio.src = cast.header.audio |
| 112 | this._audio.load() |
| 113 | } else { |
| 114 | this._timer = new SimpleTimer(new AnimationFrameTicker(), cast.header.duration) |
| 115 | } |
| 116 | |
| 117 | this._queue = new CastFrameQueue(cast, 30) |
| 118 | this._timer.onReady(() => { |
| 119 | this._loading = false |
| 120 | this._onReady.fire() |
| 121 | this._onStateChanged.fire(this.state) |
| 122 | this._timer.onTick(this._render.bind(this)) |
| 123 | this._timer.onStateChange(() => this._onStateChanged.fire(this.state)) |
| 124 | }) |
| 125 | }).catch(err => { |
| 126 | console.error(err) |
| 127 | this._error = err |
| 128 | this._onStateChanged.fire(this.state) |
| 129 | }) |
| 130 | } |
| 131 | |
| 132 | public get url(): string { return this._url } |
| 133 | public set url(url: string) { |