()
| 342 | } |
| 343 | |
| 344 | private async prepare(): Promise< |
| 345 | PlayerState & {seek: number; render: boolean} |
| 346 | > { |
| 347 | const state = { |
| 348 | ...this.playerState.current, |
| 349 | seek: this.requestedSeek, |
| 350 | render: this.requestedRender, |
| 351 | }; |
| 352 | this.requestedSeek = -1; |
| 353 | this.requestedRender = false; |
| 354 | |
| 355 | // Recalculate the project if necessary |
| 356 | if (this.requestedRecalculation) { |
| 357 | if (state.seek < 0) { |
| 358 | state.seek = this.playback.frame; |
| 359 | } |
| 360 | try { |
| 361 | await this.playback.recalculate(); |
| 362 | this.duration.current = this.playback.frame; |
| 363 | this.recalculated.dispatch(); |
| 364 | } catch (e) { |
| 365 | this.requestSeek(state.seek); |
| 366 | throw e; |
| 367 | } finally { |
| 368 | this.requestedRecalculation = false; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | // Pause if reached the end or the range is 0 |
| 373 | // Seek to the beginning for non-empty scenes |
| 374 | if ( |
| 375 | (!state.loop && this.finished && !state.paused && state.seek < 0) || |
| 376 | this.endFrame === this.startFrame |
| 377 | ) { |
| 378 | this.togglePlayback(false); |
| 379 | state.paused = true; |
| 380 | state.seek = |
| 381 | this.endFrame === this.startFrame ? state.seek : this.startFrame; |
| 382 | } |
| 383 | |
| 384 | // Seek to the beginning if looping is enabled |
| 385 | if ( |
| 386 | state.loop && |
| 387 | (state.seek > this.endFrame || (this.finished && !state.paused)) && |
| 388 | this.startFrame !== this.endTime |
| 389 | ) { |
| 390 | state.seek = this.startFrame; |
| 391 | } |
| 392 | |
| 393 | return state; |
| 394 | } |
| 395 | |
| 396 | private async run() { |
| 397 | const state = await this.prepare(); |
no test coverage detected