-
This file declares a class,
Player, instantiates it, and assigns it to a globalplayervariable. -
The
Playerclass contains four methods:constructor()playPause()skipTo()setVolume()
-
The
constructor()method sets initial values for thecurrentlyPlaying,playState,volume, andsoundObjectproperties.currentlyPlayingis set to the first item inalbum.songs.- The initial
playStateis"stopped". - The
volumeis set to the number80. - The
soundObjectinstantiates a newbuzz.soundobject using thesoundFileUrlproperty ofthis.currentlyPlaying. Thebuzzvariable doesn't appear to be initialized here, so presumably it's a dependency loaded elsewhere.
-
The
playPause()method accepts one parameter,song. It sets it tothis.currentlyPlayingby default.It checks to see if
this.currentlyPlayingis different fromsong, and if so, it:- Stops the
soundObjectproperty. - Removes the
"playing"and"paused"classes from theelementproperty ofthis.currentlyPlaying. - Sets
this.currentlyPlayingto the function's parameter,song. - Changes the
playStateproperty to"stopped". - Instantiates a new sound object using
this.currentlyPlaying, which was just updated tosong. It checks to see ifthis.playStateispausedorstopped, and if so, it: - Sets the
volumeto the default. - Toggles
playon the object. - Changes
playStatetoplayingand replaces the classpausedwithplaying. If neither of theseiffuntions trigger then an else function runs: - The
soundObjectandplayStateis set/toggled topause. playingis replaced bypausedas a class forcurrentlyPlaying.
- Stops the
-
The
skipTomethod accepts one parameter,percent. If theplayStatedoes not equalplayingit should return. Otherwise, it uses the methodsetTimeto take the input parameter ofskipToand divides it by 100 then multiplies it by thegetDurationoutput. -
The
setVolumemethod accepts one parameter,percent.- It sets
volumeto the input ofpercent. - It passes itself (
setVolume) as a method to adjust thesoundObjectto thepercentinput.
- It sets
-
getDurationreturnsthe methodgetDurationof thesoundObject. -
getTimereturnsthe methodgetTimeofsoundObject.
-
-
Save lassiter/8e690d16357ebdb8e849f342cebb7d05 to your computer and use it in GitHub Desktop.
player.js analysis
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment