Skip to content

Commit

Permalink
fix #639
Browse files Browse the repository at this point in the history
  • Loading branch information
weblancaster committed Feb 19, 2016
1 parent 03315c2 commit 5212e5f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
35 changes: 18 additions & 17 deletions app/public/js/common/playerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ app.factory('playerService', function(

userConfig.saveLastPlayedSong(trackObj);
// save queue into local storage for resume
userConfig.saveQueue(queueService.list, queueService.find(trackObjId));
userConfig.saveQueue(queueService.getAll(), queueService.find(trackObjId));

// remove the active class from player favorite icon before play new song
// TODO: this should check if the current song is already favorited
Expand All @@ -182,23 +182,24 @@ app.factory('playerService', function(
queueService.currentPosition = window.queueCurrentPosition;
trackObj = queueService.getTrack();

if (trackObj) {
utilsService.deactivateCurrentSong();
utilsService.activateCurrentSong(trackObj.songId);
if (!trackObj) {
return false;
}

if ( trackObj.songThumbnail === '' || trackObj.songThumbnail === null ) {
trackObj.songThumbnail = 'public/img/logo-short.png';
}
// update player view
this.elPlayer.setAttribute('src', trackObj.songUrl + '?client_id=' + $window.scClientId);
this.elThumb.setAttribute('src', trackObj.songThumbnail);
this.elThumb.setAttribute('alt', trackObj.songTitle);
this.elTitle.innerHTML = trackObj.songTitle;
this.elTitle.setAttribute('title', trackObj.songTitle);
this.elUser.innerHTML = trackObj.songUser;
this.elPlayer.currentTime = window.lastPlayedSongDuration;

} else return;
utilsService.deactivateCurrentSong();
utilsService.activateCurrentSong(trackObj.songId);

if ( trackObj.songThumbnail === '' || trackObj.songThumbnail === null ) {
trackObj.songThumbnail = 'public/img/logo-short.png';
}
// update player view
this.elPlayer.setAttribute('src', trackObj.songUrl + '?client_id=' + $window.scClientId);
this.elThumb.setAttribute('src', trackObj.songThumbnail);
this.elThumb.setAttribute('alt', trackObj.songTitle);
this.elTitle.innerHTML = trackObj.songTitle;
this.elTitle.setAttribute('title', trackObj.songTitle);
this.elUser.innerHTML = trackObj.songUser;
this.elPlayer.currentTime = window.lastPlayedSongDuration;
};

/**
Expand Down
13 changes: 8 additions & 5 deletions app/public/js/system/userConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ userConfig.checkAuth = function() {

console.log('User is saved');

// Make Information Readable
var lastPlayedSongDuration = +window.localStorage.lastPlayedSongDuration || 0;
var queueCurrentPosition = +window.localStorage.queueCurrentPosition;

// Expose some globals to the window
window.SC = window.localStorage.SC;
window.scAccessToken = window.localStorage.scAccessToken;
window.scClientId = window.localStorage.scClientId;
window.lastPlayedSong = window.localStorage.lastPlayedSong;
window.queue = window.localStorage.queue;
window.lastPlayedSongDuration = window.localStorage.lastPlayedSongDuration;
window.queueCurrentPosition = window.localStorage.queueCurrentPosition;
window.lastPlayedSongDuration = lastPlayedSongDuration;
window.queueCurrentPosition = queueCurrentPosition;

// Bring Soundnode to focus
window.focus();

Expand All @@ -34,7 +37,7 @@ userConfig.saveLastPlayedSong = function(trackObj) {
userConfig.saveQueue = function(queueList, currentPosition) {
window.localStorage.queue = JSON.stringify(queueList);
window.localStorage.queueCurrentPosition = currentPosition;
}
};

userConfig.saveUser = function() {
console.log('Saving user to localStorage');
Expand Down

0 comments on commit 5212e5f

Please sign in to comment.