Guest User

Untitled

a guest
Mar 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 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. It checks to see if `this.currentlyPlaying` is different from `song`, and if so, it:
  13. - Stops the `soundObject` property.
  14. - Removes the `"playing"` and `"paused"` classes from the `element` property of `this.currentlyPlaying`.
  15. - Sets `this.currentlyPlaying` to the function's parameter, `song`.
  16. - Changes the `playState` property to `"stopped"`.
  17. - Instantiates a new sound object using `this.currentlyPlaying`, which was just updated to `song`.
  18. If `this.playState` is equal to `"paused"` or is equal to `"stopped"`:
  19. - It will set volume of `this.soundObject` to `this.volume` from the `constructor` method.
  20. - It will play the `this.soundObject` property
  21. - It changes `this.playState` property to `"playing"`.
  22. - It removes the `"playing"` class from the `element` property of `this.currentlyPlaying`, and adds a class of `"playing"`.
  23. If the above conditions don't evaluate as true then:
  24. - It will `pause` the `this.soundObject` property.
  25. - It changes the `this.playState` property to `"paused"`
  26. - It removes the `"playing"` class from the `element` property of `this.currentlyPlaying`, and adds a class of `"paused"`
  27. 5. The `skipTo` method takes `percent` as a parameter.
  28. If `this.playState` is not equal to playing it will `return`
  29. - `this.soundObject` with use `setTime()` and take the parameter `percent` divide it by 100 then multiply it by `this.soundObject..getDuration()`
  30. 6. the setVolume method will take a single parameter `percent`
  31. - it will set `this.volume` equal to the `percent`
  32. - it will then `setVolume` using `percent` to `this.soundObject.
Add Comment
Please, Sign In to add comment