Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. 1. This file declares a class, `Player`, instantiates it, and assigns it to a global `const 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 getDuration() method returns this.soundObject.getDuration(). It appears to be a wrapper for a method available on this.soundObject.
  13. 5. The getTime() method returns this.soundObject.getTime(). It also appears to be a wrapper for a method available on this.soundObject.
  14. 6. The `playPause()` method accepts one parameter, `song`. It sets it to `this.currentlyPlaying` by default.
  15. * It checks to see if `this.currentlyPlaying` is different from `song`, and if so, it:
  16. - Stops the `soundObject` property.
  17. - Removes the `"playing"` and `"paused"` classes from the `element` property of `this.currentlyPlaying`.
  18. - Sets `this.currentlyPlaying` to the function's parameter, `song`.
  19. - Changes the `playState` property to `"stopped"`.
  20. - Instantiates a new sound object using `this.currentlyPlaying`, which was just updated to `song`.
  21. * Then, if `this.playState` equals `paused` or `this.playState` equals `stopped`:
  22. - Sets volume by passing property `this.volume` to method `setVolume`
  23. - Executes API method `this.soundObject.play()`
  24. - Sets property `this.playState` to `'playing'`
  25. - Removes the `"playing"` and `"paused"` classes from the `element` property of `this.currentlyPlaying`.
  26. * Otherwise:
  27. - Exucutes API method `this.soundObject.pause()`
  28. - Sets property `this.playState` to `'paused'`
  29. - Removes the `"pausesd"` and `"playing"` classes from the `element` property of `this.currentlyPlaying`.
  30. 7. Method `skipTo` accepts one parameter, `percent` to execute the following logic:
  31. * If `this.playState` does not equal `playing`, then the method executes a void return.
  32. * Otherwise, it sets the play position by passing the product
  33.     `percent / 100` × the return value of API method `this.soundObject.getDuration()`
  34. as the parameter to the API method `this.soundObject.setTime`
  35. 8. Method `setVolume` accepts one parameter, `percent` to:
  36. - set property `this.volume` to `percent`
  37. - set the volume by passing `percent` as the parameter to the API method `this.soundObject.setVolume`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement