- 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 ifthis.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
-
-
Save stacietaylorcima/455f6f1a249fdc4530735c7c45c2abd1 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
Analysis of player.js
Player
classThis file declares a class,
Player
, instantiates it, and assigns it to a globalplayer
variable.The
Player
class contains six methods:-
constructor()
-
getDuration()
-
getTime()
-
playPause()
-
skipTo()
-
setVolume()
constructor()
MethodThe
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.getDuration()
MethodBased solely on the name of this method and the property referenced, I presume it allows the player to display the length of the song.
The
getDuration()
method accesses the objectsoundObject
and returns the value of the propertygetDuration
.getTime()
MethodBased solely on the name of this method and the property referenced, I presume it allows the player to display the place in the length of the song that it is at in its duration.
The
getTime()
method accesses the objectsoundObject
and returns the value of the propertygetTime
.playPause()
MethodBased solely on the name of this method, I presume (at a high-level) it allows the player to start and stop the playing of songs.
The
playPause()
method accepts one argument,song
. It sets it tothis.currentlyPlaying
by default. Then executes the following code:If
this.currentlyPlaying
is different fromsong
, execute the following code:soundObject
even if nothing is playing."playing"
and"paused"
classes from theelement
property ofthis.currentlyPlaying
.this.currentlyPlaying
to the function's parameter,song
.playState
property to"stopped"
.soundObject
instantiates a newbuzz.sound
object using thesoundFileUrl
property ofthis.currentlyPlaying
.If the
playState
is'paused'
or'stopped'
setVolume
playState to
'playing'`"paused"
classes from theelement
property ofthis.currentlyPlaying
and adds the"playing"
class.If the
playState
is anything else besides the aforementioned"paused"
or"stopped"
, execute the following code:pause
the'soundObject'
playState
to'paused'
'playing'
class and add'paused'
classskipTo()
MethodBased solely on the name of this method, I presume it allows the user to select any point in the song to start playing from.
The
skipTo()
method takes an argumentpercent
and executes the following code:playState is not
"playing"` return that and execute the following code:percent
argument that was passed through and something withgetDuration
. I don't fully understand what that does yet.setVolume()
MethodBased solely on the name of this method and the property referenced, I presume it allows the player to display the current volume level and the user to select a new volume level.
The
setVolume()
method takes one argumentpercent
and sets the volume- GET the value of the volume
- In the
soundObject
object, SET the value of the propertysetVolume
to thepercent
argument that was passed throughplayer
VariableThe player variable instantiates a new Player something. I don't fully understand what that does yet.