-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add shuffle #61
base: master
Are you sure you want to change the base?
add shuffle #61
Changes from 5 commits
20575fd
dc08c00
c59649d
3c42459
5766ac8
4d6c6ae
2c8b258
3ff2ded
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ ngSoundManager.factory('angularPlayer', ['$rootScope', '$log', | |
|
||
var currentTrack = null, | ||
repeat = false, | ||
shuffle = false, | ||
tempTrack = [], | ||
autoPlay = true, | ||
isPlaying = false, | ||
volume = 90, | ||
|
@@ -201,6 +203,7 @@ ngSoundManager.factory('angularPlayer', ['$rootScope', '$log', | |
} | ||
//unload from soundManager | ||
soundManager.destroySound(song); | ||
|
||
//remove from playlist | ||
playlist.splice(index, 1); | ||
//once all done then broadcast | ||
|
@@ -259,16 +262,30 @@ ngSoundManager.factory('angularPlayer', ['$rootScope', '$log', | |
$log.debug("Please click on Play before this action"); | ||
return null; | ||
} | ||
var currentTrackKey = this.getIndexByValue(soundManager.soundIDs, this.getCurrentTrack()); | ||
|
||
// use shuffle track list if shuffle is true | ||
var useTrack = angular.copy(soundManager.soundIDs); | ||
if(shuffle === true){ | ||
useTrack = tempTrack; | ||
} | ||
|
||
var currentTrackKey = this.getIndexByValue(useTrack, this.getCurrentTrack()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
var nextTrackKey = +currentTrackKey + 1; | ||
var nextTrack = soundManager.soundIDs[nextTrackKey]; | ||
var nextTrack = useTrack[nextTrackKey]; | ||
if(typeof nextTrack !== 'undefined') { | ||
this.playTrack(nextTrack); | ||
} else { | ||
// generate shuffle track list | ||
if(shuffle === true && isPlaying === true){ | ||
tempTrack = angular.copy(soundManager.soundIDs); | ||
tempTrack = (tempTrack).sort(function() { return 0.5 - Math.random(); }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
$rootScope.$broadcast('music:tempTrack', tempTrack); | ||
} | ||
|
||
//if no next track found | ||
if(repeat === true) { | ||
//start first track if repeat is on | ||
this.playTrack(soundManager.soundIDs[0]); | ||
this.playTrack(useTrack[0]); | ||
} else { | ||
//breadcase not playing anything | ||
isPlaying = false; | ||
|
@@ -281,9 +298,16 @@ ngSoundManager.factory('angularPlayer', ['$rootScope', '$log', | |
$log.debug("Please click on Play before this action"); | ||
return null; | ||
} | ||
var currentTrackKey = this.getIndexByValue(soundManager.soundIDs, this.getCurrentTrack()); | ||
|
||
// use shuffle track list if shuffle is true | ||
var useTrack = angular.copy(soundManager.soundIDs); | ||
if(shuffle === true){ | ||
useTrack = tempTrack; | ||
} | ||
|
||
var currentTrackKey = this.getIndexByValue(useTrack, this.getCurrentTrack()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
var prevTrackKey = +currentTrackKey - 1; | ||
var prevTrack = soundManager.soundIDs[prevTrackKey]; | ||
var prevTrack = useTrack[prevTrackKey]; | ||
if(typeof prevTrack !== 'undefined') { | ||
this.playTrack(prevTrack); | ||
} else { | ||
|
@@ -312,6 +336,36 @@ ngSoundManager.factory('angularPlayer', ['$rootScope', '$log', | |
getRepeatStatus: function() { | ||
return repeat; | ||
}, | ||
shuffleToggle: function() { | ||
if(shuffle === true) { | ||
shuffle = false; | ||
tempTrack = angular.copy(soundManager.soundIDs); | ||
} else { | ||
shuffle = true; | ||
tempTrack = angular.copy(soundManager.soundIDs); | ||
tempTrack = (tempTrack).sort(function() { return 0.5 - Math.random(); }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
} | ||
$rootScope.$broadcast('music:shuffle', shuffle); | ||
$rootScope.$broadcast('music:tempTrack', tempTrack); | ||
}, | ||
getShuffleStatus: function() { | ||
return shuffle; | ||
}, | ||
playShuffle: function(){ | ||
var trackToPlay = null; | ||
shuffle = true; | ||
tempTrack = angular.copy(soundManager.soundIDs); | ||
tempTrack = (tempTrack).sort(function() { return 0.5 - Math.random(); }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
$rootScope.$broadcast('music:shuffle', shuffle); | ||
$rootScope.$broadcast('music:tempTrack', tempTrack); | ||
|
||
if(tempTrack.length === 0) { | ||
$log.debug('playlist is empty!'); | ||
return; | ||
} | ||
trackToPlay = tempTrack[0]; | ||
this.initPlayTrack(trackToPlay); | ||
}, | ||
getVolume: function() { | ||
return volume; | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
ngSoundManager.directive('shuffleMusic', ['angularPlayer', function (angularPlayer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
return { | ||
restrict: "EA", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mixed double and single quotes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mixed double and single quotes. |
||
link: function (scope, element, attrs) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'attrs' is defined but never used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'attrs' is defined but never used. |
||
|
||
element.bind('click', function (event) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'event' is defined but never used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'event' is defined but never used. |
||
angularPlayer.shuffleToggle(); | ||
}); | ||
|
||
scope.shuffle = angularPlayer.getShuffleStatus(); | ||
scope.$on('music:shuffle', function (event, data) { | ||
scope.$apply(function () { | ||
scope.shuffle = data; | ||
}); | ||
}); | ||
} | ||
}; | ||
}]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
ngSoundManager.directive('shuffleAllMusic', ['angularPlayer', function (angularPlayer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
return { | ||
restrict: "EA", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mixed double and single quotes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mixed double and single quotes. |
||
link: function (scope, element, attrs) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'attrs' is defined but never used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'attrs' is defined but never used. |
||
|
||
element.bind('click', function (event) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'event' is defined but never used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'event' is defined but never used. |
||
angularPlayer.playShuffle(); | ||
}); | ||
|
||
scope.shuffle = angularPlayer.getShuffleStatus(); | ||
} | ||
}; | ||
}]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long.