Adds back setting the volume up / down using the keyboard
- Adds a volume field to the player service. It is set directly, no need for get/set... - Adds a watcher in player-directive to set jPlayer's volume accordingly - Adds turnVolumeUp and turnVolumeDown methods to the main scope. For the moment they are fine there, we'll maybe move them to the player service if they are called by anything else. - Adds get/save/delete for the volume in the persistence service.
This commit is contained in:
parent
8529e331a2
commit
a85865371c
8 changed files with 196 additions and 57 deletions
|
@ -348,6 +348,26 @@ angular.module('JamStash')
|
|||
}
|
||||
};
|
||||
|
||||
$scope.turnVolumeUp = function () {
|
||||
var volume = player.volume;
|
||||
if ((volume+0.1) > 1 || volume < 0) {
|
||||
volume = 0.9;
|
||||
}
|
||||
volume += 0.1;
|
||||
player.volume = volume;
|
||||
persistence.saveVolume(volume);
|
||||
};
|
||||
|
||||
$scope.turnVolumeDown = function () {
|
||||
var volume = player.volume;
|
||||
if (volume > 1 || (volume-0.1) < 0) {
|
||||
volume = 0.1;
|
||||
}
|
||||
volume -= 0.1;
|
||||
player.volume = volume;
|
||||
persistence.saveVolume(volume);
|
||||
};
|
||||
|
||||
$rootScope.addToJukebox = function (id) {
|
||||
if (globals.settings.Debug) { console.log("LOAD JUKEBOX"); }
|
||||
$.ajax({
|
||||
|
@ -416,6 +436,7 @@ angular.module('JamStash')
|
|||
persistence.loadQueue();
|
||||
persistence.loadTrackPosition();
|
||||
}
|
||||
player.volume = persistence.getVolume();
|
||||
}
|
||||
/* End Startup */
|
||||
}]);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
describe("Main controller", function() {
|
||||
'use strict';
|
||||
|
||||
var scope, mockGlobals, player, utils;
|
||||
var controllerParams, $controller, scope, mockGlobals, player, utils, persistence;
|
||||
beforeEach(function() {
|
||||
mockGlobals = {
|
||||
settings: {
|
||||
|
@ -17,14 +17,20 @@ describe("Main controller", function() {
|
|||
|
||||
// Mock the player service
|
||||
player = jasmine.createSpyObj("player", ["togglePause"]);
|
||||
player.queue = [];
|
||||
player.volume = 1.0;
|
||||
|
||||
inject(function ($controller, $rootScope, _$document_, _$window_, _$location_, _$cookieStore_, _utils_, globals, _model_, _notifications_, _locker_, _Page_) {
|
||||
// Mock the persistence service
|
||||
persistence = jasmine.createSpyObj("persistence", ["getVolume", "saveVolume"]);
|
||||
|
||||
inject(function (_$controller_, $rootScope, _$document_, _$window_, _$location_, _$cookieStore_, _utils_, globals, _model_, _notifications_, _Page_) {
|
||||
scope = $rootScope.$new();
|
||||
utils = _utils_;
|
||||
|
||||
spyOn(utils, "switchTheme");
|
||||
|
||||
$controller('AppController', {
|
||||
$controller = _$controller_;
|
||||
controllerParams = {
|
||||
$scope: scope,
|
||||
$rootScope: $rootScope,
|
||||
$document: _$document_,
|
||||
|
@ -36,12 +42,11 @@ describe("Main controller", function() {
|
|||
model: _model_,
|
||||
notifications: _notifications_,
|
||||
player: player,
|
||||
locker: _locker_,
|
||||
persistence: persistence,
|
||||
Page: _Page_
|
||||
};
|
||||
});
|
||||
});
|
||||
player.queue = [];
|
||||
});
|
||||
|
||||
xdescribe("updateFavorite -", function() {
|
||||
|
||||
|
@ -70,6 +75,11 @@ describe("Main controller", function() {
|
|||
|
||||
});
|
||||
|
||||
describe("", function () {
|
||||
beforeEach(function() {
|
||||
$controller('AppController', controllerParams);
|
||||
});
|
||||
|
||||
it("given that the global setting 'ShowQueue' is true, when the playing queue's length changes and is not empty, it shows the queue", function() {
|
||||
mockGlobals.settings.ShowQueue = true;
|
||||
player.queue = [{
|
||||
|
@ -96,4 +106,54 @@ describe("Main controller", function() {
|
|||
expect(player.togglePause).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("When I turn the volume up,", function() {
|
||||
it("it sets the player's volume up by 10% and saves it using the persistence service", function() {
|
||||
player.volume = 0.5;
|
||||
|
||||
scope.turnVolumeUp();
|
||||
|
||||
expect(player.volume).toBe(0.6);
|
||||
expect(persistence.saveVolume).toHaveBeenCalledWith(0.6);
|
||||
});
|
||||
|
||||
it("if the player's resulting volume won't be between 0 and 1, it sets it to 1", function() {
|
||||
player.volume = 5.91488;
|
||||
|
||||
scope.turnVolumeUp();
|
||||
|
||||
expect(player.volume).toBe(1.0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("When I turn the volume down,", function() {
|
||||
it("it sets the player's volume down by 10% and saves it using the persistence service", function() {
|
||||
player.volume = 0.5;
|
||||
|
||||
scope.turnVolumeDown();
|
||||
|
||||
expect(player.volume).toBe(0.4);
|
||||
expect(persistence.saveVolume).toHaveBeenCalledWith(0.4);
|
||||
});
|
||||
|
||||
it("if the player's resulting volume won't be between 0 and 1, it sets it to 0", function() {
|
||||
player.volume = 5.91488;
|
||||
|
||||
scope.turnVolumeDown();
|
||||
|
||||
expect(player.volume).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("When starting up,", function() {
|
||||
it("it loads the volume from the persistence service and sets the player service's volume with it", function() {
|
||||
persistence.getVolume.and.returnValue(0.551835);
|
||||
|
||||
$controller('AppController', controllerParams);
|
||||
|
||||
expect(persistence.getVolume).toHaveBeenCalled();
|
||||
expect(player.volume).toBe(0.551835);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -54,5 +54,17 @@ angular.module('jamstash.persistence', ['jamstash.settings', 'jamstash.player.se
|
|||
locker.forget('CurrentQueue');
|
||||
if (globals.settings.Debug) { console.log('Removing Play Queue from localStorage'); }
|
||||
};
|
||||
|
||||
this.getVolume = function () {
|
||||
return locker.get('Volume');
|
||||
};
|
||||
|
||||
this.saveVolume = function (volume) {
|
||||
locker.put('Volume', volume);
|
||||
};
|
||||
|
||||
this.deleteVolume = function () {
|
||||
locker.forget('Volume');
|
||||
};
|
||||
}]);
|
||||
|
||||
|
|
|
@ -85,19 +85,37 @@ describe("Persistence service", function() {
|
|||
expect(notifications.updateMessage).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getVolume -", function() {
|
||||
it("Given that we previously saved the volume in local Storage, it retrieves it", function() {
|
||||
fakeStorage = { 'Volume': 0.46582 };
|
||||
|
||||
var volume = persistence.getVolume();
|
||||
|
||||
expect(locker.get).toHaveBeenCalledWith('Volume');
|
||||
expect(volume).toBe(0.46582);
|
||||
});
|
||||
|
||||
describe("save from localStorage -", function() {
|
||||
it("Given that we didn't save the volume in local Storage, it returns undefined", function() {
|
||||
var volume = persistence.getVolume();
|
||||
|
||||
expect(locker.get).toHaveBeenCalledWith('Volume');
|
||||
expect(volume).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("save to localStorage -", function() {
|
||||
beforeEach(function() {
|
||||
spyOn(locker, "put");
|
||||
});
|
||||
|
||||
it("it saves the current track's position in local Storage", function() {
|
||||
it("saves the current track's position in local Storage", function() {
|
||||
persistence.saveTrackPosition(song);
|
||||
expect(locker.put).toHaveBeenCalledWith('CurrentSong', song);
|
||||
});
|
||||
|
||||
it("it saves the playing queue in local Storage", function() {
|
||||
it("saves the playing queue in local Storage", function() {
|
||||
player.queue = [
|
||||
{ id: 1245 },
|
||||
{ id: 7465 },
|
||||
|
@ -106,6 +124,11 @@ describe("Persistence service", function() {
|
|||
persistence.saveQueue();
|
||||
expect(locker.put).toHaveBeenCalledWith('CurrentQueue', player.queue);
|
||||
});
|
||||
|
||||
it("saves the volume in local Storage", function() {
|
||||
persistence.saveVolume(0.05167);
|
||||
expect(locker.put).toHaveBeenCalledWith('Volume', 0.05167);
|
||||
});
|
||||
});
|
||||
|
||||
describe("remove from localStorage -", function() {
|
||||
|
@ -113,14 +136,19 @@ describe("Persistence service", function() {
|
|||
spyOn(locker, "forget");
|
||||
});
|
||||
|
||||
it("it deletes the current track from local Storage", function() {
|
||||
it("deletes the current track from local Storage", function() {
|
||||
persistence.deleteTrackPosition();
|
||||
expect(locker.forget).toHaveBeenCalledWith('CurrentSong');
|
||||
});
|
||||
|
||||
it("it deletes the saved playing queue from local Storage", function() {
|
||||
it("deletes the saved playing queue from local Storage", function() {
|
||||
persistence.deleteQueue();
|
||||
expect(locker.forget).toHaveBeenCalledWith('CurrentQueue');
|
||||
});
|
||||
|
||||
it("deletes the saved volume from local Storage", function() {
|
||||
persistence.deleteVolume();
|
||||
expect(locker.forget).toHaveBeenCalledWith('Volume');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<link href="styles/Mobile.css" rel="stylesheet" type="text/css" data-name="main" />
|
||||
<link href="" rel="stylesheet" type="text/css" data-name="theme" />
|
||||
</head>
|
||||
<body ui-keypress="{'space': 'togglePause()'}">
|
||||
<body ui-keypress="{'32 179': 'togglePause()', '187 61 43': 'turnVolumeUp()', '189 95 45': 'turnVolumeDown()'}">
|
||||
<div id="container">
|
||||
<div id="header">
|
||||
<div id="messages">
|
||||
|
|
|
@ -159,6 +159,13 @@ angular.module('jamstash.player.directive', ['jamstash.player.service', 'jamstas
|
|||
}
|
||||
});
|
||||
|
||||
scope.$watch(function () {
|
||||
return playerService.volume;
|
||||
}, function (newVal) {
|
||||
$player.jPlayer('volume', newVal);
|
||||
if (globals.settings.Debug) { console.log('Volume: ' + Math.round(newVal * 100) + '%'); }
|
||||
});
|
||||
|
||||
scope.$watch(function () {
|
||||
return globals.settings.SaveTrackPosition;
|
||||
}, function (newVal) {
|
||||
|
|
|
@ -22,6 +22,7 @@ describe("jplayer directive", function() {
|
|||
$delegate.pauseSong = false;
|
||||
$delegate.restartSong = false;
|
||||
$delegate.loadSong = false;
|
||||
$delegate.volume = 1.0;
|
||||
$delegate.getPlayingSong = jasmine.createSpy('getPlayingSong').and.callFake(function() {
|
||||
return playingSong;
|
||||
});
|
||||
|
@ -137,8 +138,12 @@ describe("jplayer directive", function() {
|
|||
});
|
||||
});
|
||||
|
||||
it("When the player service's restartSong flag is true, it restarts the current song, resets the restart flag to false and resets the scrobbled flag to false", function() {
|
||||
describe("", function() {
|
||||
beforeEach(function() {
|
||||
$.fn.jPlayer.and.stub();
|
||||
});
|
||||
|
||||
it("When the player service's restartSong flag is true, it restarts the current song, resets the restart flag to false and resets the scrobbled flag to false", function() {
|
||||
playerService.restartSong = true;
|
||||
scope.scrobbled = true;
|
||||
scope.$apply();
|
||||
|
@ -149,15 +154,13 @@ describe("jplayer directive", function() {
|
|||
});
|
||||
|
||||
it("When the player service's pauseSong is true, it pauses the current song", function() {
|
||||
$.fn.jPlayer.and.stub();
|
||||
playerService.pauseSong = true;
|
||||
scope.$apply();
|
||||
|
||||
expect($player.jPlayer).toHaveBeenCalledWith('pause');
|
||||
});
|
||||
|
||||
it("Given that the current song is paused, when I toggle pause again, it plays the song ", function() {
|
||||
$.fn.jPlayer.and.stub();
|
||||
it("Given that the current song is paused, when the player service's pauseSong becomes false, it plays the song ", function() {
|
||||
playerService.pauseSong = true;
|
||||
scope.$apply();
|
||||
|
||||
|
@ -166,6 +169,13 @@ describe("jplayer directive", function() {
|
|||
expect($player.jPlayer).toHaveBeenCalledWith('play');
|
||||
});
|
||||
|
||||
it("When the player service's volume changes, it sets jPlayer's volume", function() {
|
||||
playerService.volume = 0.2034;
|
||||
scope.$apply();
|
||||
expect($player.jPlayer).toHaveBeenCalledWith('volume', 0.2034);
|
||||
});
|
||||
});
|
||||
|
||||
describe("When jplayer has finished the current song,", function() {
|
||||
var ended;
|
||||
beforeEach(function() {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Manages the player and playing queue. Use it to play a song, go to next track or add songs to the queue.
|
||||
*/
|
||||
angular.module('jamstash.player.service', ['jamstash.settings', 'angular-underscore/utils'])
|
||||
angular.module('jamstash.player.service', ['angular-underscore/utils', 'jamstash.settings'])
|
||||
|
||||
.factory('player', ['globals', function (globals) {
|
||||
'use strict';
|
||||
|
@ -16,6 +16,7 @@ angular.module('jamstash.player.service', ['jamstash.settings', 'angular-undersc
|
|||
pauseSong: false,
|
||||
restartSong: false,
|
||||
loadSong: false,
|
||||
volume: 1.0,
|
||||
|
||||
play: function(song) {
|
||||
// Find the song's index in the queue, if it's in there
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue