Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum State = {
- Created,
- Loading,
- Stopped,
- Playing,
- Discarded,
- };
- class MediaPlayer {
- private state = State.Created;
- play(): boolean {
- // Validation
- if (this.state !== State.Stopped) {
- console.warn('play() called in invalid state');
- return false;
- }
- // Execution
- this.startPlayback();
- // Transition
- this.state = State.Playing;
- // Result
- return true;
- }
- }
Add Comment
Please, Sign In to add comment