-
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
.
- Stops the
- It checks to see if
this.playState
is equal topaused
orstopped
, if so, it starts playing by doing the following:- Calls the
setVolume
method ofthis.soundObject
and passesthis.volume
as a parameter. - Calls the
play
method ofthis.soundObject
. - Sets
this.playState
to"playing"
. - Removes the class
"paused"
fromthis.currentlyPlaying.element
and adds the class"playing"
.
- Calls the
- Else it pauses playback by doing the following:
- Calls the
pause
method inthis.soundObject
. - Sets
this.playState
to"paused"
. - Removes the
"playing"
class fromthis.currentlyplaying.element
and adds the"paused"
class.
- Calls the
- It checks to see if
-
The
skipTo()
method accepts one parameter,percent
. It skips the song to the percentage value ofpercent
.- It checks if
this.playState !== "playing"
and exitsskipTo
iftrue
. - The
setTime
method ofthis.soundObject
is called with a parameter:(percent/100) * this.soundObject.getDuration()
.
- It checks if
-
The
setVolume()
method accepts one parameter,percent
. It sets the volume of the player to the passed percentage:- It sets
this.volume
topercent
. - It calls the
setVolume
method ofthis.soundObject
and passespercent
as a parameter.
- It sets
-
-
Save DamianRivas/18e1933706124b22767e3e15c4703602 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