Guest User

Untitled

a guest
May 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. 1. This file declares a class, `Player`, instantiates it, and assigns it to a global `player` variable.
  2. 2. The `Player` class contains four methods:
  3. - `constructor()`
  4. - `playPause()`
  5. - `skipTo()`
  6. - `setVolume()`
  7. 3. The `constructor()` method sets initial values for the `currentlyPlaying`, `playState`, `volume`, and `soundObject` properties.
  8. - `currentlyPlaying` is set to the first item in `album.songs`.
  9. - The initial `playState` is `"stopped"`.
  10. - The `volume` is set to the number `80`.
  11. - The `soundObject` instantiates a new `buzz.sound` object using the `soundFileUrl` property of `this.currentlyPlaying`. The `buzz` variable doesn't appear to be initialized here, so presumably it's a dependency loaded elsewhere.
  12. 4. The `playPause()` method accepts one parameter, `song`. It sets it to `this.currentlyPlaying` by default.
  13.  
  14. It checks to see if `this.currentlyPlaying` is different from `song`, and if so, it:
  15. - Stops the `soundObject` property.
  16. - Removes the `"playing"` and `"paused"` classes from the `element` property of `this.currentlyPlaying`.
  17. - Sets `this.currentlyPlaying` to the function's parameter, `song`.
  18. - Changes the `playState` property to `"stopped"`.
  19. - Instantiates a new sound object using `this.currentlyPlaying`, which was just updated to `song`.
  20.  
  21. It checks to see if `this.playState`is equal to `paused` or `stopped`.
  22. If so, it:
  23. - Sets the volume to `this.volume`, which was updated as 80.
  24. - Plays the `soundObject` property.
  25. - Changes the `playState` property to `"playing"`,
  26. - Removes the `"paused"` class from the `element` property of `this.currentlyPlaying`
  27. - Adds the `"playing"` class to the `element` property of `this.currentlyPlaying`
  28.  
  29. If not, it:
  30. - Pause the `soundObject` property.
  31. - Changes the `playState` property to `"paused"`;
  32. - Removes the `"playing"` class from the `element` property of `this.currentlyPlaying`
  33. - Adds the `"paused"` class to the `element` property of `this.currentlyPlaying`
  34.  
  35. 5. The `skipTo()` method accepts one parameter, `percent`. It checks if `this.playState` is equal to `"playing"`.
  36. If not, the method will be exited.
  37. If yes, it multiply the `percent` argument by the value of `this.soundObject.getDuration()`, and sets it as the time of the `soundObject` property.
  38.  
  39. 6. The `setVolume()` method accepts one parameter, `percent`. It:
  40. - Sets the value of `this.volume` property as the `percent` argument
  41. - Sets the volume of `this.soundObject` as `this.volume`
Add Comment
Please, Sign In to add comment