Skip to content

Commit 068a64d

Browse files
committed
Merge pull request #351 from Soundnode/shuffle
add shuffle feat. closes #226
2 parents 6e1c816 + b1222bb commit 068a64d

File tree

5 files changed

+50
-19
lines changed

5 files changed

+50
-19
lines changed

app/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ <h4 id="playerUser" class="player_user"></h4>
159159
<span class="player_duration" id="player-duration"></span>
160160
</div>
161161
<div class="player_controls">
162+
<span class="player_shuffle" ng-click="shuffle($event)">
163+
<i class="fa fa-random thin"></i>
164+
</span>
162165
<span class="player_prevSong" ng-click="prevSong($event)">
163166
<i class="fa fa-step-backward thin"></i>
164167
</span>
@@ -169,8 +172,8 @@ <h4 id="playerUser" class="player_user"></h4>
169172
<span class="player_nextSong" ng-click="nextSong($event)">
170173
<i class="fa fa-step-forward thin"></i>
171174
</span>
172-
<span class="player_queueList" ng-controller="QueueCtrl" ng-click="toggleQueue($event)">
173-
<i class="fa fa-list"></i>
175+
<span class="player_queueList" ng-click="toggleQueue($event)">
176+
<i class="fa fa-list thin"></i>
174177
</span>
175178
</div>
176179
<div class="player_volume">

app/public/js/common/playerService.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ app.factory('playerService', function($rootScope, $log, $timeout, $window, $stat
2727

2828
$rootScope.isSongPlaying = false;
2929
$rootScope.isPlaylistPlaying = false;
30+
$rootScope.shuffle= false;
31+
32+
/**
33+
* Get a number betweem the min index and max index
34+
* in the Queue array
35+
* @returns {number} [index in array]
36+
*/
37+
function shuffle() {
38+
var max = queueService.size() - 1;
39+
var min = 0;
40+
41+
queueService.currentPosition = Math.floor(Math.random() * (max - min) + min);
42+
}
3043

3144
/**
3245
* Get siblings of current song
@@ -67,6 +80,10 @@ app.factory('playerService', function($rootScope, $log, $timeout, $window, $stat
6780
}
6881
}
6982

83+
/**
84+
* Activate track in view based on trackId
85+
* @param trackId [contain track id]
86+
*/
7087
function activateCurrentSong(trackId) {
7188
var el = document.querySelector('span[data-song-id="' + trackId + '"]');
7289

@@ -221,9 +238,12 @@ app.factory('playerService', function($rootScope, $log, $timeout, $window, $stat
221238
* @method playPrevSong
222239
*/
223240
player.playPrevSong = function() {
224-
queueService.prev();
241+
if ( $rootScope.shuffle ) {
242+
shuffle();
243+
} else {
244+
queueService.prev();
245+
}
225246
this.playNewSong();
226-
//$rootScope.$broadcast('activateQueue');
227247
};
228248

229249
/**
@@ -233,9 +253,12 @@ app.factory('playerService', function($rootScope, $log, $timeout, $window, $stat
233253
* @method playPrevSong
234254
*/
235255
player.playNextSong = function() {
236-
queueService.next();
256+
if ( $rootScope.shuffle ) {
257+
shuffle();
258+
} else {
259+
queueService.next();
260+
}
237261
this.playNewSong();
238-
//$rootScope.$broadcast('activateQueue');
239262
};
240263

241264
/**

app/public/js/common/queueCtrl.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,4 @@ app.controller('QueueCtrl', function($scope, $rootScope, queueService, $log, $ti
4646
}
4747
};
4848

49-
50-
$scope.toggleQueue = function($event) {
51-
52-
if ( $scope.data.length < 1 ) {
53-
return;
54-
}
55-
56-
$event.currentTarget.classList.toggle('active');
57-
document.querySelector('.queueList').classList.toggle('active');
58-
59-
//$scope.activateTrackInQueue();
60-
}
6149
});

app/public/js/player/playerCtrl.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
app.controller('PlayerCtrl', function ($scope, $rootScope, playerService, hotkeys, $log, $timeout) {
44
$scope.imgPath = 'public/img/temp-playing.png';
5+
56
$timeout(function() {
67
if(window.localStorage.volume) {
78
$scope.volume = window.localStorage.volume;
@@ -59,6 +60,21 @@ app.controller('PlayerCtrl', function ($scope, $rootScope, playerService, hotkey
5960
}
6061
};
6162

63+
$scope.shuffle = function($event) {
64+
$event.currentTarget.classList.toggle('active');
65+
if ( $rootScope.shuffle ) {
66+
$rootScope.shuffle = false;
67+
} else {
68+
$rootScope.shuffle = true;
69+
}
70+
};
71+
72+
$scope.toggleQueue = function($event) {
73+
74+
$event.currentTarget.classList.toggle('active');
75+
document.querySelector('.queueList').classList.toggle('active');
76+
};
77+
6278

6379
/*
6480
* Add native media shortcuts

app/public/stylesheets/sass/_components/_player.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@
199199
flex-grow: 1;
200200
}
201201

202+
.player_shuffle.active,
202203
.player_queueList.active {
203204
& .fa {
204205
color: $scColor;
205206
}
206-
}
207+
}

0 commit comments

Comments
 (0)