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) { angular.forEach(items, function (item, key) {
var song = mapSong(key, item, server, dir, identifier, coverart); var song = mapSong(key, item, server, dir, identifier, coverart);
if (song) { if (song) {
$rootScope.queue.push(song); player.queue.push(song);
} }
}); });
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true); notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
} else if (action == 'play') { } else if (action == 'play') {
$rootScope.queue = []; player.queue = [];
angular.forEach(items, function (item, key) { angular.forEach(items, function (item, key) {
var song = mapSong(key, item, server, dir, identifier, coverart); var song = mapSong(key, item, server, dir, identifier, coverart);
if (song) { if (song) {
$rootScope.queue.push(song); player.queue.push(song);
} }
}); });
var next = $rootScope.queue[0]; var next = player.queue[0];
player.play(next); player.play(next);
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true); notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
} else { } else {

View file

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

View file

@ -1,18 +1,25 @@
describe("Main controller", function() { describe("Main controller", function() {
'use strict'; 'use strict';
var scope, $rootScope, utils, globals, notifications, player, locker; var scope, mockGlobals, player, utils;
beforeEach(function() { beforeEach(function() {
module('JamStash'); mockGlobals = {
settings: {
ShowQueue: false,
Debug: true
}
};
inject(function ($controller, _$rootScope_, _$document_, _$window_, _$location_, _$cookieStore_, _utils_, _globals_, _model_, _notifications_, _player_, _locker_) { module('JamStash', function($provide) {
$rootScope = _$rootScope_; $provide.value('globals', mockGlobals);
});
inject(function ($controller, $rootScope, _$document_, _$window_, _$location_, _$cookieStore_, _utils_, globals, _model_, _notifications_, _player_, _locker_, _Page_) {
scope = $rootScope.$new(); scope = $rootScope.$new();
utils = _utils_;
globals = _globals_;
notifications = _notifications_;
player = _player_; player = _player_;
locker = _locker_; utils = _utils_;
spyOn(utils, "switchTheme");
$controller('AppController', { $controller('AppController', {
$scope: scope, $scope: scope,
@ -24,11 +31,13 @@ describe("Main controller", function() {
utils: utils, utils: utils,
globals: globals, globals: globals,
model: _model_, model: _model_,
notifications: notifications, notifications: _notifications_,
player: player, player: player,
locker: locker locker: _locker_,
Page: _Page_
}); });
}); });
player.queue = [];
}); });
xdescribe("updateFavorite -", function() { xdescribe("updateFavorite -", function() {
@ -57,4 +66,16 @@ describe("Main controller", function() {
xdescribe("toggleSetting -", 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', swfPath: 'bower_components/jplayer/dist/jplayer/jquery.jplayer.swf',
wmode: 'window', wmode: 'window',
solution: audioSolution, solution: audioSolution,
supplied: 'mp3', supplied: 'mp3, oga, m4a',
preload: 'auto', preload: 'auto',
errorAlerts: false, errorAlerts: false,
warningAlerts: false, warningAlerts: false,
@ -57,6 +57,7 @@ angular.module('jamstash.player.directive', ['jamstash.player.service', 'jamstas
// Load more random tracks // Load more random tracks
subsonic.getRandomSongs().then(function (songs) { subsonic.getRandomSongs().then(function (songs) {
playerService.addSongs(songs).songEnded(); playerService.addSongs(songs).songEnded();
notifications.updateMessage('Auto Play Activated...', true);
}); });
} else { } else {
playerService.songEnded(); playerService.songEnded();
@ -95,7 +96,15 @@ angular.module('jamstash.player.directive', ['jamstash.player.service', 'jamstas
if($.fancybox.isOpen) { if($.fancybox.isOpen) {
scope.fancyboxOpenImage(newSong.coverartfull); 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) { if(playerService.loadSong === true) {
// Do not play, only load // Do not play, only load
playerService.loadSong = false; playerService.loadSong = false;
@ -155,7 +164,7 @@ angular.module('jamstash.player.directive', ['jamstash.player.service', 'jamstas
} }
}; };
// Startup // Startup
timerid = 0; timerid = 0;
scope.currentSong = {}; scope.currentSong = {};
scope.scrobbled = false; scope.scrobbled = false;
@ -163,6 +172,14 @@ angular.module('jamstash.player.directive', ['jamstash.player.service', 'jamstas
updatePlayer(); updatePlayer();
scope.startSavePosition(); 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 } //end link
}; };
}]); }]);

View file

@ -53,7 +53,10 @@ describe("jplayer directive", function() {
beforeEach(function() { beforeEach(function() {
// To avoid errors breaking the test, we stub jPlayer // To avoid errors breaking the test, we stub jPlayer
$.fn.jPlayer.and.stub(); $.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() { 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); 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() { 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(); 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; mockGlobals.settings.AutoPlay = true;
spyOn(subsonic, "getRandomSongs").and.returnValue(deferred.promise); spyOn(subsonic, "getRandomSongs").and.returnValue(deferred.promise);
spyOn(notifications, "updateMessage");
playerService.isLastSongPlaying.and.returnValue(true); playerService.isLastSongPlaying.and.returnValue(true);
$player.trigger(ended); $player.trigger(ended);
@ -138,6 +154,7 @@ describe("jplayer directive", function() {
expect(playerService.isLastSongPlaying).toHaveBeenCalled(); expect(playerService.isLastSongPlaying).toHaveBeenCalled();
expect(subsonic.getRandomSongs).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') { if (action == 'add') {
angular.forEach(items, function (item, key) { 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); notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') { } else if (action == 'play') {
$rootScope.queue = []; player.queue = [];
angular.forEach(items, function (item, key) { 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); player.play(next);
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else { } else {
@ -757,18 +757,18 @@ angular.module('jamstash.subsonic.service', ['jamstash.settings', 'jamstash.util
if (action == 'add') { if (action == 'add') {
angular.forEach(items, function (item, key) { angular.forEach(items, function (item, key) {
if (item.status != "skipped") { 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); notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') { } else if (action == 'play') {
$rootScope.queue = []; player.queue = [];
angular.forEach(items, function (item, key) { angular.forEach(items, function (item, key) {
if (item.status != "skipped") { 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); player.play(next);
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else { } else {