Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add missing Sound features .seek(), .duration, & getTotalPlaybackDuration() #2340

Merged
merged 7 commits into from
Jun 5, 2022

Conversation

eonarheim
Copy link
Member

@eonarheim eonarheim commented Jun 5, 2022

===:clipboard: PR Checklist :clipboard:===

  • 📌 issue exists in github for these changes
  • 🔬 existing tests still pass
  • 🙈 code conforms to the style guide
  • 📐 new tests written and passing / old tests updated with new scenario(s)
  • 📄 changelog entry added (or not needed)

==================

This PR adds the ability to ex.Sound.seek() to a specific position in the sound, it also adds the ex.Sound.getTotalPlaybackDuration() so you may know how long in seconds the sound file is. Lastly ex.Sound.duration if set will limit the duration of the clip from where played();

In order to accomplish this, ex.Sound() was refactored using a small ex.StateMachine implementation

Example

const machine = ex.StateMachine.create({
  start: 'STOPPED',
  states: {
    PLAYING: {
      onEnter: () => {
        console.log("playing");
      },
      transitions: ['STOPPED', 'PAUSED']
    },
    STOPPED: {
      onEnter: () => {
        console.log("stopped");
      },
      transitions: ['PLAYING']
    },
    PAUSED: {
      onEnter: () => {
        console.log("paused")
      },
      transitions: ['PLAYING', 'STOPPED']
    }
  }
});

Changes:

  • Adds ex.Sound.seek()
  • Adds ex.Sound.duration
  • Adds ex.Sound.getTotalPlaybackDuration()
  • Adds new ex.StateMachine()

@github-actions github-actions bot added the enhancement Label applied to enhancements or improvements to existing features label Jun 5, 2022
@eonarheim eonarheim changed the title feat: Add Sound.seek() & total duration + refactor sound w/ state machine feat: Add missing Sound features .seek(), .duration, & getTotalPlaybackDuration() + refactor sound w/ state machine Jun 5, 2022
@eonarheim eonarheim changed the title feat: Add missing Sound features .seek(), .duration, & getTotalPlaybackDuration() + refactor sound w/ state machine feat: Add missing Sound features .seek(), .duration, & getTotalPlaybackDuration() Jun 5, 2022
@eonarheim eonarheim merged commit fb79d5b into main Jun 5, 2022
@eonarheim eonarheim deleted the feature/add-seek-and-total-duration branch June 5, 2022 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Label applied to enhancements or improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant