Skip to content

Commit

Permalink
fix: Error if Sound.getTotalPlaybackDuration called before load
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Jan 28, 2024
1 parent 3631ad5 commit a9e8132
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fixed issue where `ex.Sound.getTotalPlaybackDuration()` would crash if not loaded, now logs friendly warning
- Fixed issue where an empty constructor on `new ex.Label()` would crash
- Fixed issue where pointer events did not work properly when using [[ScreenElement]]s
- Fixed issue where debug draw was not accurate when using *AndFill suffixed [[DisplayMode]]s
Expand Down
5 changes: 5 additions & 0 deletions src/engine/Resources/Sound/Sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ export class Sound implements Audio, Loadable<AudioBuffer> {
}

public getTotalPlaybackDuration() {
if (!this.isLoaded()) {
this.logger.warnOnce(`Sound from ${this.path} is not loaded, cannot return total playback duration.` +
`Did you forget to add Sound to a loader? https://excaliburjs.com/docs/loaders/`);
return 0;
}
return this.data.duration;
}

Expand Down

0 comments on commit a9e8132

Please sign in to comment.