jxnblk/plangular — pull request #45 by watadarkstar (2014-11-25 21:33:39+00:00)
Title: Fixes #41

- The issue was that the "Player becomes unresponsive when changing views." This is because the player remembers its current state. This becomes problematic for a few reasons. One, on page change if the player is playing it continues to play (I am unsure if this is intentional but I find this user experience to be broken because the user can't stop the audio unless the page has a player on it). Two, when the user returns to a page with a player and presses pause it causes a out of bound error. This is because this.tracks[i] is undefined due to the player remember the current state the index is increased by one from its previous state and because it was not reset, it is now outside of the bounds of the array.
- My solution is to reset the player when the directive is destroyed. I reset all values to their initial value except for the data. The data is left untouched so that we can avoid duplicate calls to the sound cloud API. I also load the track into the player when its found in the player's data object, otherwise the player will not have all the tracks because we reset the array on the directive's destroy callback.