Repository: motion-canvas/motion-canvas
File: packages/core/src/app/Player.ts (TypeScript)

Code before:
  }

  private async prepare(): Promise<
    PlayerState & {seek: number; render: boolean}
  > {
    const state = {
      ...this.playerState.current,
      seek: this.requestedSeek,
      render: this.requestedRender,
    };
    this.requestedSeek = -1;
    this.requestedRender = false;

    // Recalculate the project if necessary
    if (this.requestedRecalculation) {
      if (state.seek < 0) {
        state.seek = this.playback.frame;
      }
      try {
        await this.playback.recalculate();
        this.duration.current = this.playback.frame;

        const sounds: Sound[] = [];
        for (let i = 0; i < this.project.scenes.length; i++) {
          const scene = this.playback.onScenesRecalculated.current[i];
          sounds.push(...(<Sound[]>(<any>scene.sounds).sounds));
        }
        this.audioPool.setupPools(sounds);
        this.audioPool.setTime(this.status.time);

        this.recalculated.dispatch();
      } catch (e) {
        this.requestSeek(state.seek);
        throw e;
      } finally {
        this.requestedRecalculation = false;
      }
    }

    // Pause if reached the end or the range is 0
    // Seek to the beginning for non-empty scenes
    if (
      (!state.loop && this.finished && !state.paused && state.seek < 0) ||
      this.endFrame === this.startFrame
    ) {
      this.togglePlayback(false);
      state.paused = true;
      state.seek =
        this.endFrame === this.startFrame ? state.seek : this.startFrame;
    }


Review comment (suggestion):
You can make `Sounds.sounds` `public` and mark it with:
```ts
/**
 * @internal
 */
 ```
 Or, if you want to be fancy, you can make a getter that returns `readonly Sound[]`:
 ```ts
public getSounds(): readonly Sound[] {
  return this.sounds;
}
```

Code after:
  }

  private async prepare(): Promise<
    PlayerState & {seek: number; render: boolean}
  > {
    const state = {
      ...this.playerState.current,
      seek: this.requestedSeek,
      render: this.requestedRender,
    };
    this.requestedSeek = -1;
    this.requestedRender = false;

    // Recalculate the project if necessary
    if (this.requestedRecalculation) {
      if (state.seek < 0) {
        state.seek = this.playback.frame;
      }
      try {
        await this.playback.recalculate();
        this.duration.current = this.playback.frame;

        const sounds: Sound[] = [];
        for (const scene of this.playback.onScenesRecalculated.current) {
          sounds.push(...scene.sounds.getSounds());
        }
        await this.audioPool.setupPool(sounds);

        this.recalculated.dispatch();
      } catch (e) {
        this.requestSeek(state.seek);
        throw e;
      } finally {
        this.requestedRecalculation = false;
      }
    }

    // Pause if reached the end or the range is 0
    // Seek to the beginning for non-empty scenes
    if (
      (!state.loop && this.finished && !state.paused && state.seek < 0) ||
      this.endFrame === this.startFrame
    ) {
      this.togglePlayback(false);
      state.paused = true;
      state.seek =
        this.endFrame === this.startFrame ? state.seek : this.startFrame;
    }

    // Seek to the beginning if looping is enabled
    if (