Adds back support of oga and m4a

- Fixes the various remaining calls to $rootScope.queue. They now use the player service.
- main-controller.js watches the player's queue and shows the queue on change (if the global setting is true)
- Fixes the animation of the scrubber width. It is now done in the player directive.
This commit is contained in:
Hyzual 2015-01-11 20:17:13 +01:00
parent 95c791fa40
commit 09fb66f2fe
6 changed files with 97 additions and 54 deletions

View file

@ -180,19 +180,19 @@ angular.module('jamstash.archive.service', ['jamstash.settings', 'jamstash.model
angular.forEach(items, function (item, key) {
var song = mapSong(key, item, server, dir, identifier, coverart);
if (song) {
$rootScope.queue.push(song);
player.queue.push(song);
}
});
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
player.queue = [];
angular.forEach(items, function (item, key) {
var song = mapSong(key, item, server, dir, identifier, coverart);
if (song) {
$rootScope.queue.push(song);
player.queue.push(song);
}
});
var next = $rootScope.queue[0];
var next = player.queue[0];
player.play(next);
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
} else {

View file

@ -5,7 +5,6 @@ angular.module('JamStash')
$rootScope.settings = globals.settings;
$rootScope.song = [];
$rootScope.queue = [];
$rootScope.playingSong = null;
$rootScope.MusicFolders = [];
$rootScope.Genres = [];
@ -103,19 +102,15 @@ angular.module('JamStash')
}
};
$scope.$watchCollection('queue', function(newItem, oldItem) {
// TODO: Hyz: Replace
if (oldItem.length != newItem.length
&& globals.settings.ShowQueue) {
$rootScope.showQueue();
$scope.$watchCollection(function () {
return player.queue;
}, function(newQueue) {
console.log('newQueue', newQueue);
if (newQueue !== undefined && newQueue.length > 0 && globals.settings.ShowQueue) {
$scope.showQueue();
}
/*
for (var index in newCol) {
var item = newCol[index];
item.order = parseInt(index) + 1;
}
*/
});
$rootScope.showQueue = function () {
$('#SideBar').css('display', 'block');
$('#right-component').removeClass('lgcolumn_expanded');
@ -164,13 +159,6 @@ angular.module('JamStash')
});
};
$('#audiocontainer .scrubber').mouseover(function (e) {
$('.audiojs .scrubber').stop().animate({ height: '8px' });
});
$('#audiocontainer .scrubber').mouseout(function (e) {
$('.audiojs .scrubber').stop().animate({ height: '4px' });
});
$(document).on("click", ".message", function(){
$(this).remove();
});
@ -178,7 +166,7 @@ angular.module('JamStash')
// Global Functions
window.onbeforeunload = function () {
if (!globals.settings.Debug) {
if ($rootScope.queue.length > 0) {
if (player.queue.length > 0) {
return "You're about to end your session, are you sure?";
}
}
@ -190,8 +178,8 @@ angular.module('JamStash')
$scope.dragEnd = function (e, ui) {
var start = ui.item.data('start'),
end = ui.item.index();
$rootScope.queue.splice(end, 0,
$rootScope.queue.splice(start, 1)[0]);
player.queue.splice(end, 0,
player.queue.splice(start, 1)[0]);
$scope.$apply();
};
$(document).on( 'click', 'message', function() {
@ -284,10 +272,10 @@ angular.module('JamStash')
};
$rootScope.playAll = function (songs) {
// TODO: Hyz: Replace
$rootScope.queue = [];
player.queue = [];
$rootScope.selectAll(songs);
$rootScope.addSongsToQueue();
var next = $rootScope.queue[0];
var next = player.queue[0];
player.play(next);
};
$rootScope.playFrom = function (index, songs) {
@ -299,9 +287,9 @@ angular.module('JamStash')
item.selected = true;
});
if ($scope.selectedSongs.length > 0) {
$rootScope.queue = [];
player.queue = [];
$rootScope.addSongsToQueue();
var next = $rootScope.queue[0];
var next = player.queue[0];
player.play(next);
}
};
@ -309,7 +297,7 @@ angular.module('JamStash')
// TODO: Hyz: Replace
if ($scope.selectedSongs.length !== 0) {
angular.forEach($scope.selectedSongs, function (item, key) {
$rootScope.queue.push(item);
player.queue.push(item);
item.selected = false;
});
notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true);

View file

@ -1,18 +1,25 @@
describe("Main controller", function() {
'use strict';
var scope, $rootScope, utils, globals, notifications, player, locker;
var scope, mockGlobals, player, utils;
beforeEach(function() {
module('JamStash');
mockGlobals = {
settings: {
ShowQueue: false,
Debug: true
}
};
inject(function ($controller, _$rootScope_, _$document_, _$window_, _$location_, _$cookieStore_, _utils_, _globals_, _model_, _notifications_, _player_, _locker_) {
$rootScope = _$rootScope_;
module('JamStash', function($provide) {
$provide.value('globals', mockGlobals);
});
inject(function ($controller, $rootScope, _$document_, _$window_, _$location_, _$cookieStore_, _utils_, globals, _model_, _notifications_, _player_, _locker_, _Page_) {
scope = $rootScope.$new();
utils = _utils_;
globals = _globals_;
notifications = _notifications_;
player = _player_;
locker = _locker_;
utils = _utils_;
spyOn(utils, "switchTheme");
$controller('AppController', {
$scope: scope,
@ -24,11 +31,13 @@ describe("Main controller", function() {
utils: utils,
globals: globals,
model: _model_,
notifications: notifications,
notifications: _notifications_,
player: player,
locker: locker
locker: _locker_,
Page: _Page_
});
});
player.queue = [];
});
xdescribe("updateFavorite -", function() {
@ -57,4 +66,16 @@ describe("Main controller", function() {
xdescribe("toggleSetting -", function() {
});
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 = [{
id: 684
}];
spyOn(scope, "showQueue");
scope.$apply();
expect(scope.showQueue).toHaveBeenCalled();
});
});

View file

@ -28,7 +28,7 @@ angular.module('jamstash.player.directive', ['jamstash.player.service', 'jamstas
swfPath: 'bower_components/jplayer/dist/jplayer/jquery.jplayer.swf',
wmode: 'window',
solution: audioSolution,
supplied: 'mp3',
supplied: 'mp3, oga, m4a',
preload: 'auto',
errorAlerts: false,
warningAlerts: false,
@ -57,6 +57,7 @@ angular.module('jamstash.player.directive', ['jamstash.player.service', 'jamstas
// Load more random tracks
subsonic.getRandomSongs().then(function (songs) {
playerService.addSongs(songs).songEnded();
notifications.updateMessage('Auto Play Activated...', true);
});
} else {
playerService.songEnded();
@ -95,7 +96,15 @@ angular.module('jamstash.player.directive', ['jamstash.player.service', 'jamstas
if($.fancybox.isOpen) {
scope.fancyboxOpenImage(newSong.coverartfull);
}
$player.jPlayer('setMedia', {'mp3': newSong.url});
var media = {};
if (newSong.suffix === 'oga') {
media= { oga: newSong.url };
} else if (newSong.suffix === 'm4a') {
media= { m4a: newSong.url };
} else if (newSong.suffix === 'mp3') {
media= { mp3: newSong.url };
}
$player.jPlayer('setMedia', media);
if(playerService.loadSong === true) {
// Do not play, only load
playerService.loadSong = false;
@ -163,6 +172,14 @@ angular.module('jamstash.player.directive', ['jamstash.player.service', 'jamstas
updatePlayer();
scope.startSavePosition();
//TODO: Hyz: Maybe move to another directive dedicated to the scrubber ?
$('#audiocontainer .scrubber').mouseover(function () {
$('.audiojs .scrubber').stop().animate({ height: '8px' });
});
$('#audiocontainer .scrubber').mouseout(function () {
$('.audiojs .scrubber').stop().animate({ height: '4px' });
});
} //end link
};
}]);

View file

@ -53,7 +53,10 @@ describe("jplayer directive", function() {
beforeEach(function() {
// To avoid errors breaking the test, we stub jPlayer
$.fn.jPlayer.and.stub();
playingSong = {url: 'https://gantry.com/antemarital/vigorless?a=oropharyngeal&b=killcrop#eviscerate'};
playingSong = {
url: 'https://gantry.com/antemarital/vigorless?a=oropharyngeal&b=killcrop#eviscerate',
suffix: 'mp3'
};
});
it("it sets jPlayer's media, stores the song for future scrobbling and sets the page title with the song", function() {
@ -104,6 +107,18 @@ describe("jplayer directive", function() {
expect(scope.fancyboxOpenImage).toHaveBeenCalledWith(playingSong.coverartfull);
});
it("if the song's suffix is 'm4a', it sets jPlayer up with this format", function() {
playingSong.suffix = 'm4a';
scope.$apply();
expect($.fn.jPlayer).toHaveBeenCalledWith('setMedia', {'m4a': 'https://gantry.com/antemarital/vigorless?a=oropharyngeal&b=killcrop#eviscerate'});
});
it("if the song's suffix is 'oga', it sets jPlayer up with this format", function() {
playingSong.suffix = 'oga';
scope.$apply();
expect($.fn.jPlayer).toHaveBeenCalledWith('setMedia', {'oga': 'https://gantry.com/antemarital/vigorless?a=oropharyngeal&b=killcrop#eviscerate'});
});
});
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() {
@ -127,9 +142,10 @@ describe("jplayer directive", function() {
expect(playerService.songEnded).toHaveBeenCalled();
});
it("given that the last song of the queue is playing and that the global setting AutoPlay is true, it asks subsonic for random tracks and notifies the player service that the song has ended", function() {
it("given that the last song of the queue is playing and that the global setting AutoPlay is true, it asks subsonic for random tracks, notifies the player service that the song has ended and notifies the user", function() {
mockGlobals.settings.AutoPlay = true;
spyOn(subsonic, "getRandomSongs").and.returnValue(deferred.promise);
spyOn(notifications, "updateMessage");
playerService.isLastSongPlaying.and.returnValue(true);
$player.trigger(ended);
@ -138,6 +154,7 @@ describe("jplayer directive", function() {
expect(playerService.isLastSongPlaying).toHaveBeenCalled();
expect(subsonic.getRandomSongs).toHaveBeenCalled();
expect(notifications.updateMessage).toHaveBeenCalledWith('Auto Play Activated...', true);
});
});

View file

@ -359,15 +359,15 @@ angular.module('jamstash.subsonic.service', ['jamstash.settings', 'jamstash.util
}
if (action == 'add') {
angular.forEach(items, function (item, key) {
$rootScope.queue.push(map.mapSong(item));
player.queue.push(map.mapSong(item));
});
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
player.queue = [];
angular.forEach(items, function (item, key) {
$rootScope.queue.push(map.mapSong(item));
player.queue.push(map.mapSong(item));
});
var next = $rootScope.queue[0];
var next = player.queue[0];
player.play(next);
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
@ -757,18 +757,18 @@ angular.module('jamstash.subsonic.service', ['jamstash.settings', 'jamstash.util
if (action == 'add') {
angular.forEach(items, function (item, key) {
if (item.status != "skipped") {
$rootScope.queue.push(map.mapPodcast(item));
player.queue.push(map.mapPodcast(item));
}
});
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
player.queue = [];
angular.forEach(items, function (item, key) {
if (item.status != "skipped") {
$rootScope.queue.push(map.mapPodcast(item));
player.queue.push(map.mapPodcast(item));
}
});
var next = $rootScope.queue[0];
var next = player.queue[0];
player.play(next);
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {