Guest User

Untitled

a guest
Dec 18th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. enum State = {
  2. Created,
  3. Loading,
  4. Stopped,
  5. Playing,
  6. Discarded,
  7. };
  8.  
  9. class MediaPlayer {
  10. private state = State.Created;
  11.  
  12. play(): boolean {
  13. // Validation
  14. if (this.state !== State.Stopped) {
  15. console.warn('play() called in invalid state');
  16. return false;
  17. }
  18.  
  19. // Execution
  20. this.startPlayback();
  21.  
  22. // Transition
  23. this.state = State.Playing;
  24.  
  25. // Result
  26. return true;
  27. }
  28. }
Add Comment
Please, Sign In to add comment