Skip to content

Instantly share code, notes, and snippets.

@kolbykskk
Forked from R-V-S/player-js-analysis.md
Created December 4, 2017 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolbykskk/a5832056cf9e8fc1d4d8f11c9b9adb44 to your computer and use it in GitHub Desktop.
Save kolbykskk/a5832056cf9e8fc1d4d8f11c9b9adb44 to your computer and use it in GitHub Desktop.
player.js analysis
  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.
@kolbykskk
Copy link
Author

kolbykskk commented Dec 4, 2017

  • Checks to see if playState is paused or stopped, if stopped it...
    -- turns on the volume
    -- plays the song
    -- sets the playState to playing
    -- removes the paused class from the DOM and adds the playing class

  • Otherwise, if a song is already playing, it will,
    -- pause the song
    -- sets the playState to pause
    -- removes the playing class and adds the paused class

  1. skipTo takes a % variable
  • checks to see if a song is NOT playing. If no song is playing then do nothing. If there is a song playing then...
    -- set the time in the song to the % that was passed into the method
  1. setVolume takes a % variable
  • sets the volume property to the % that was passed in
  • changes the volume of the song to the % that was passed in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment