Add "repeat one" playmode (#47)

* loading spinner while searching

* initialize $scope.loading =  false

* ng-src - > src

* add "repeat one" playmode

* when repeat one is on,  repeat this track

* rename playmodeCount

* switchMode comment

* change icon name to "icn-repeatone"

* turn off shuffle when repeat one is on

* playmode switch comment
This commit is contained in:
Richcard Ho 2016-05-29 12:21:48 +10:00 committed by Listen 1
parent 3ecef3c524
commit 358dab5563
3 changed files with 63 additions and 22 deletions

View File

@ -55,7 +55,17 @@
app.filter('playmode_title', function() {
return function(input) {
return input ? '随机' : '顺序';
switch(input){
case 0:
return "顺序";
break;
case 1:
return "随机";
break;
case 2:
return "单曲循环";
break;
}
};
});
@ -503,6 +513,30 @@
$scope.scrobbleTrackId = null;
$scope.scrobbleTimer = new Timer();
function switchMode(mode){
//playmode 0:loop 1:shuffle 2:repeat one
switch(mode){
case 0:
if (angularPlayer.getShuffle()) {
angularPlayer.toggleShuffle();
}
angularPlayer.setRepeatOneStatus(false);
break;
case 1:
if (!angularPlayer.getShuffle()) {
angularPlayer.toggleShuffle();
}
angularPlayer.setRepeatOneStatus(false);
break;
case 2:
if (angularPlayer.getShuffle()) {
angularPlayer.toggleShuffle();
}
angularPlayer.setRepeatOneStatus(true);
break
}
}
$scope.loadLocalSettings = function() {
var defaultSettings = {"playmode": 0, "nowplaying_track_id": -1, "volume": 90};
var localSettings = localStorage.getObject('player-settings');
@ -514,16 +548,8 @@
$scope.settings = localSettings;
}
// apply settings
var shuffleSetting;
if ($scope.settings.playmode == 1) {
shuffleSetting = true;
}
else {
shuffleSetting = false;
}
if (angularPlayer.getShuffle() != shuffleSetting) {
angularPlayer.toggleShuffle();
}
switchMode($scope.settings.playmode);
$scope.volume = $scope.settings.volume;
if($scope.volume == null) {
@ -553,14 +579,9 @@
}
$scope.changePlaymode = function() {
// loop: 0, shuffle: 1
angularPlayer.toggleShuffle();
if (angularPlayer.getShuffle()) {
$scope.settings.playmode = 1;
}
else {
$scope.settings.playmode = 0;
}
var playmodeCount = 3;
$scope.settings.playmode = ($scope.settings.playmode+1)%playmodeCount;
switchMode($scope.settings.playmode);
$scope.saveLocalSettings();
};
@ -856,7 +877,7 @@
hotkeys.add({
combo: 's',
description: '切换播放模式(顺序/随机',
description: '切换播放模式(顺序/随机/单曲循环',
callback: function() {
$scope.changePlaymode();
}

View File

@ -4428,6 +4428,7 @@ ngSoundManager.factory('angularPlayer', ['$rootScope', '$log',
trackProgress = 0,
playlist = [],
shuffle = false,
repeatOne = false,
shufflelist= [],
shuffleCount = 0,
shuffleIndex = -1,
@ -4505,7 +4506,12 @@ ngSoundManager.factory('angularPlayer', ['$rootScope', '$log',
var injector = elem.injector();
//get the service.
var angularPlayer = injector.get('angularPlayer');
angularPlayer.nextTrack();
// repeat current track
if(repeatOne === true) {
angularPlayer.playTrack(this.id);
} else {
angularPlayer.nextTrack();
}
$rootScope.$broadcast('track:id', currentTrack);
}
}
@ -4849,6 +4855,19 @@ ngSoundManager.factory('angularPlayer', ['$rootScope', '$log',
getRepeatStatus: function() {
return repeat;
},
repeatOneToggle: function() {
if(repeatOne === true) {
repeatOne = false;
} else {
repeatOne = true;
}
},
getRepeatOneStatus: function() {
return repeatOne;
},
setRepeatOneStatus: function(value) {
repeatOne = value ;
},
getVolume: function() {
return volume;
},

View File

@ -204,6 +204,7 @@
<input type="text" id="search-input" class="form-control" ng-model="keywords" placeholder="输入歌曲名,歌手或专辑" ng-model-options="{debounce: 500}" />
<ul class="nav nav-tabs">
<li ng-class="{'active':isActiveTab(0)}" ng-click="changeTab(0)"><a>网易</a></li>
<li ng-class="{'active':isActiveTab(1)}" ng-click="changeTab(1)"><a href="#">虾米</a></li>
@ -371,7 +372,7 @@
<div class="ctrl">
<a class="icn icn-add" ng-click="showDialog(0, currentPlaying)" title="添加到歌单">添加到歌单</a>
<a class="icn" ng-class="{ 'icn-shuffle': settings.playmode == 1, 'icn-loop': settings.playmode == 0 }" title="{{ settings.playmode | playmode_title }}(s)" ng-click="changePlaymode()"></a>
<a class="icn" ng-class="{ 'icn-repeatone': settings.playmode == 2,'icn-shuffle': settings.playmode == 1, 'icn-loop': settings.playmode == 0 }" title="{{ settings.playmode | playmode_title }}(s)" ng-click="changePlaymode()"></a>
<a class="icn icn-list" title="列表(l)" ng-click="togglePlaylist()"></a>
</div>