Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. This file declares a class, `Player`, instantiates it, and assigns it to a global `player` variable.
- 2. The `Player` class contains four methods:
- - `constructor()`
- - `playPause()`
- - `skipTo()`
- - `setVolume()`
- 3. The `constructor()` method sets initial values for the `currentlyPlaying`, `playState`, `volume`, and `soundObject` properties.
- - `currentlyPlaying` is set to the first item in `album.songs`.
- - The initial `playState` is `"stopped"`.
- - The `volume` is set to the number `80`.
- - 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.
- 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:
- - Stops the `soundObject` property.
- - Removes the `"playing"` and `"paused"` classes from the `element` property of `this.currentlyPlaying`.
- - Sets `this.currentlyPlaying` to the function's parameter, `song`.
- - Changes the `playState` property to `"stopped"`.
- - Instantiates a new sound object using `this.currentlyPlaying`, which was just updated to `song`.
- - if the `playState` property is either `"paused"` or `"stopped"`, it:
- - Sets the volume of `soundObject` property to volume 80.
- - Plays the `soundObject` property.
- - Changes the `playState` property to `"playing"`.
- - Removes the `"paused"` class from the `element` property of `this.currentlyPlaying` and adds the `"playing"` class.
- - if the `playState` property is neither `"paused"` nor `"stopped"`, it:
- - Pauses the `soundObject` property.
- - Changes the `playState` property to `"paused"`.
- - Removes the `"playing"` class from the `element` property of `this.currentlyPlaying` and adds the `"paused"` class.
- 5. The `skipTo` method accepts one parameter, `percent`. If the `playState` property is not `"playing"`, it:
- - returns `this.soundObject.setTime( (percent / 100) * this.soundObject.getDuration()) `.
- - It sets the time of the `soundObject` property to a percentage multiplied by the `getDuration() method`.
- 6. The `setVolume` method accepts one parameter, `percent`. It sets it to `this.volume` by default and sets the volume of the `soundObject` property.
Add Comment
Please, Sign In to add comment