-
This file declares a class,
Player
, instantiates it, and assigns it to a globalplayer
variable. -
The
Player
class contains four methods:constructor()
playPause()
skipTo()
setVolume()
-
The
constructor()
method sets initial values for thecurrentlyPlaying
,playState
,volume
, andsoundObject
properties.currentlyPlaying
is set to the first item inalbum.songs
.- The initial
playState
is"stopped"
. - The
volume
is set to the number80
. - The
soundObject
instantiates a newbuzz.sound
object using thesoundFileUrl
property ofthis.currentlyPlaying
. Thebuzz
variable 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.currentlyPlaying
by default.It checks to see if
this.currentlyPlaying
is different fromsong
, and if so, it:- Stops the
soundObject
property. - Removes the
"playing"
and"paused"
classes from theelement
property ofthis.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 tosong
. It checks to see ifthis.playState
ispaused
orstopped
, and if so, it: - Sets the
volume
to the default. - Toggles
play
on the object. - Changes
playState
toplaying
and replaces the classpaused
withplaying
. If neither of theseif
funtions trigger then an else function runs: - The
soundObject
andplayState
is set/toggled topause
. playing
is replaced bypaused
as a class forcurrentlyPlaying
.
- Stops the
-
The
skipTo
method accepts one parameter,percent
. If theplayState
does not equalplaying
it should return. Otherwise, it uses the methodsetTime
to take the input parameter ofskipTo
and divides it by 100 then multiplies it by thegetDuration
output. -
The
setVolume
method accepts one parameter,percent
.- It sets
volume
to the input ofpercent
. - It passes itself (
setVolume
) as a method to adjust thesoundObject
to thepercent
input.
- It sets
-
getDuration
returns
the methodgetDuration
of thesoundObject
. -
getTime
returns
the methodgetTime
ofsoundObject
.
-
-
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