Starts rewriting the player service.

The API is simplified: we can play a song, restart the currently playing song, load a song (that'll be used only by local storage), play the next track or the previous track.

As a result, I changed all the calls to playSong(false, song) which are now just play(song)
This commit is contained in:
Hyzual 2014-12-10 23:46:57 +01:00
parent 226a768987
commit e51961c167
13 changed files with 145 additions and 446 deletions

View file

@ -193,7 +193,7 @@ angular.module('jamstash.archive.service', ['jamstash.settings', 'jamstash.model
}
});
var next = $rootScope.queue[0];
player.playSong(false, next);
player.play(next);
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
} else {
content.album = [];

View file

@ -279,7 +279,7 @@
$rootScope.selectAll(songs);
$rootScope.addSongsToQueue();
var next = $rootScope.queue[0];
player.playSong(false, next);
player.play(next);
};
$rootScope.playFrom = function (index, songs) {
var from = songs.slice(index,songs.length);
@ -292,7 +292,7 @@
$rootScope.queue = [];
$rootScope.addSongsToQueue();
var next = $rootScope.queue[0];
player.playSong(false, next);
player.play(next);
}
};
$rootScope.addSongsToQueue = function () {
@ -446,7 +446,7 @@
// Load Saved Song
var song = angular.fromJson(localStorage.getItem('CurrentSong'));
if (song) {
player.playSong(true, song);
player.load(song);
// Load Saved Queue
var items = angular.fromJson(localStorage.getItem('CurrentQueue'));
if (items) {

View file

@ -1,4 +1,4 @@
<li class="row song" ng-repeat="o in song" ng-click="selectSong(o)" ng-dblclick="playSong(false, o)" ng-class="{'selected': o.selected, 'playing': o.playing}">
<li class="row song" ng-repeat="o in song" ng-click="selectSong(o)" ng-dblclick="playSong(o)" ng-class="{'selected': o.selected, 'playing': o.playing}">
<div class="itemactions">
<a class="remove" href="" title="Remove Song" ng-click="removeSongFromQueue(o)" stop-event="click"></a>
<a href="" title="Favorite" ng-class="{'favorite': o.starred, 'rate': !o.starred}" ng-click="updateFavorite(o)" stop-event="click"></a>

View file

@ -1,404 +1,49 @@
angular.module('jamstash.player.service', ['jamstash.utils', 'jamstash.settings', 'jamstash.model',
'jamstash.notifications'])
.service('player', ['$rootScope', '$window', 'utils', 'globals', 'model', 'notifications',
function ($rootScope, $window, utils, globals, model, notifications) {
/**
* jamstash.player.service Module
*
* Enables app-wide control of the behavior of the player directive.
*/
angular.module('jamstash.player.service', ['jamstash.settings'])
.factory('player', function () {
'use strict';
var player1 = globals.Player1;
var player2 = '#playdeck_2';
var scrobbled = false;
var timerid = 0;
function getNextSong (previous) {
var song;
if (globals.settings.Debug) { console.log('Getting Next Song > ' + 'Queue length: ' + $rootScope.queue.length); }
if ($rootScope.queue.length > 0) {
angular.forEach($rootScope.queue, function (item, key) {
if (item.playing === true) {
song = item;
} else {
item.playing = false;
}
});
var index = $rootScope.queue.indexOf(song);
var next;
if (previous) {
next = $rootScope.queue[index - 1];
} else {
next = $rootScope.queue[index + 1];
}
if (typeof next != 'undefined') {
if (globals.settings.Debug) { console.log('Next Song: ' + next.id); }
return next;
} else {
return false;
}
} else {
return false;
}
}
this.nextTrack = function () {
var next = getNextSong();
if (next) {
this.playSong(false, next);
}
};
this.previousTrack = function () {
var next = getNextSong(true);
if (next) {
this.playSong(false, next);
} else {
this.restartSong();
}
};
this.defaultPlay = function (data, event) {
if (typeof $(player1).data("jPlayer") == 'undefined') {
this.nextTrack();
}
if (typeof $(player1).data("jPlayer") != 'undefined' && globals.settings.Jukebox) {
if ($(player1).data("jPlayer").status.paused) {
$rootScope.sendToJukebox('start');
} else {
$rootScope.sendToJukebox('stop');
}
}
};
function internalScrobbleSong(submission) {
if ($rootScope.loggedIn && submission) {
var id = $rootScope.playingSong.id;
if (globals.settings.Debug) { console.log('Scrobble Song: ' + id); }
$.ajax({
url: globals.BaseURL() + '/scrobble.view?' + globals.BaseParams() + '&id=' + id + "&submission=" + submission,
method: 'GET',
dataType: globals.settings.Protocol,
timeout: 10000,
success: function () {
scrobbled = true;
}
});
}
}
this.startSaveTrackPosition = function () {
if (globals.settings.SaveTrackPosition) {
if (timerid !== 0) {
clearInterval(timerid);
}
timerid = $window.setInterval(function () {
if (globals.settings.SaveTrackPosition) {
$rootScope.saveTrackPosition();
}
}, 30000);
}
};
this.toggleMute = function () {
//var audio = typeof $(player1).data("jPlayer") != 'undefined' ? true : false;
var audio = $(player1).data("jPlayer");
if (typeof audio != 'undefined') {
if (audio.options.muted) {
audio.options.muted = false;
} else {
audio.options.muted = true;
}
}
};
this.saveTrackPosition = function () {
//var audio = typeof $(player1).data("jPlayer") != 'undefined' ? true : false;
var audio = $(player1).data("jPlayer");
if (typeof audio != 'undefined') {
if (audio.status.currentTime > 0 && audio.status.paused === false) {
var song;
angular.forEach($rootScope.queue, function (item, key) {
if (item.playing === true) {
song = item;
}
});
if (song) {
var position = audio.status.currentTime;
if (position !== null) {
$('#action_SaveProgress').fadeTo("slow", 0).delay(500).fadeTo("slow", 1).delay(500).fadeTo("slow", 0).delay(500).fadeTo("slow", 1);
song.position = position;
// Save Queue
if (utils.browserStorageCheck()) {
try {
var songStr = angular.toJson(song);
localStorage.setItem('CurrentSong', songStr);
if (globals.settings.Debug) { console.log('Saving Current Position: ' + songStr); }
var html = localStorage.getItem('CurrentQueue');
if ($rootScope.queue.length > 0) {
var current = $rootScope.queue;
if (current != html) {
localStorage.setItem('CurrentQueue', angular.toJson(current));
if (globals.settings.Debug) { console.log('Saving Queue: ' + current.length + ' characters'); }
}
}
} catch (e) {
if (e == QUOTA_EXCEEDED_ERR) {
alert('Quota exceeded!');
}
}
} else {
if (globals.settings.Debug) { console.log('HTML5::loadStorage not supported on your browser'); }
}
}
}
}
} else {
if (globals.settings.Debug) { console.log('Saving Queue: No Audio Loaded'); }
}
};
var player = {
queue: [],
currentlyPlayingIndex: -1,
this.deleteCurrentQueue = function (data) {
if (utils.browserStorageCheck()) {
localStorage.removeItem('CurrentQueue');
utils.setValue('CurrentSong', null, false);
if (globals.settings.Debug) { console.log('Removing Play Queue'); }
} else {
if (globals.settings.Debug) { console.log('HTML5::loadStorage not supported on your browser, ' + html.length + ' characters'); }
}
};
this.restartSong = function (loadonly, data) {
var audio = $(player1).data("jPlayer");
audio.play(0);
};
this.playSong = function (loadonly, data) {
console.log('playSong');
if (globals.settings.Debug) { console.log('Play: ' + JSON.stringify(data, null, 2)); }
angular.forEach($rootScope.queue, function(item, key) {
item.playing = false;
});
data.playing = true;
data.selected = false;
if ($rootScope.playingSong != null && data.id != $rootScope.playingSong.id && $.fancybox.isOpen) {
utils.fancyboxOpenImage(data.coverartfull);
}
$rootScope.playingSong = data;
var id = data.id;
var url = data.url;
var position = data.position;
var title = data.name;
var album = data.album;
var artist = data.artist;
var suffix = data.suffix;
var specs = data.specs;
var coverartthumb = data.coverartthumb;
var coverartfull = data.coverartfull;
var starred = data.starred;
$('#playermiddle').css('visibility', 'visible');
$('#songdetails').css('visibility', 'visible');
if (globals.settings.Jukebox) {
$rootScope.addToJukebox(id);
this.loadjPlayer(player1, url, suffix, true, position);
} else {
this.loadjPlayer(player1, url, suffix, loadonly, position);
}
var spechtml = '';
var playerData = $(player1).data();
if(playerData !== null) {
var jplayerData = playerData.jPlayer;
for (var i = 0; i < jplayerData.solutions.length; i++) {
var solution = jplayerData.solutions[i];
if (jplayerData[solution].used) {
spechtml += "<strong class=\"codesyntax\">" + solution + "</strong> is";
spechtml += " currently being used with<strong>";
angular.forEach(jplayerData[solution].support, function (format) {
if (jplayerData[solution].support[format]) {
spechtml += " <strong class=\"codesyntax\">" + format + "</strong>";
}
});
spechtml += "</strong> support";
}
}
}
$('#SMStats').html(spechtml);
scrobbled = false;
if ($rootScope.queue.length > 0) {
$('#queue').stop().scrollTo('#' + id, 400);
}
if (globals.settings.NotificationSong && !loadonly) {
notifications.showNotification(coverartthumb, utils.toHTML.un(title), utils.toHTML.un(artist + ' - ' + album), 'text', '#NextTrack');
}
if (globals.settings.ScrollTitle) {
utils.scrollTitle(utils.toHTML.un(artist) + ' - ' + utils.toHTML.un(title));
} else {
utils.setTitle(utils.toHTML.un(artist) + ' - ' + utils.toHTML.un(title));
}
//utils.safeApply();
if(!$rootScope.$root.$$phase) {
$rootScope.$apply();
}
};
this.loadjPlayer = function (el, url, suffix, loadonly, position) {
// jPlayer Setup
var volume = 1;
if (utils.getValue('Volume')) {
volume = parseFloat(utils.getValue('Volume'));
}
var audioSolution = "html,flash";
if (globals.settings.ForceFlash) {
audioSolution = "flash,html";
}
if (globals.settings.Debug) { console.log('Setting Audio Solution: ' + audioSolution); }
//var salt = Math.floor(Math.random() * 100000);
//url += '&salt=' + salt;
var muted = false;
if (globals.settings.Jukebox) { muted = true;}
$(el).jPlayer("destroy");
$.jPlayer.timeFormat.showHour = true;
$(el).jPlayer({
swfPath: "js/plugins/jplayer",
wmode: "window",
solution: audioSolution,
supplied: suffix,
volume: volume,
muted: muted,
errorAlerts: false,
warningAlerts: false,
cssSelectorAncestor: "",
cssSelector: {
play: ".PlayTrack",
pause: ".PauseTrack",
seekBar: "#audiocontainer .scrubber",
playBar: "#audiocontainer .progress",
mute: "#action_Mute",
unmute: "#action_UnMute",
volumeMax: "#action_VolumeMax",
currentTime: "#played",
duration: "#duration"
play: function(song) {
song.playing = true;
console.log('play()');
},
ready: function () {
console.log("File Suffix: " + suffix);
if (suffix == 'oga') {
$(this).jPlayer("setMedia", {
oga: url
});
} else if (suffix == 'm4a') {
$(this).jPlayer("setMedia", {
m4a: url
});
} else if (suffix == 'mp3') {
$(this).jPlayer("setMedia", {
mp3: url
});
}
if (!loadonly) { // Start playing
$(this).jPlayer("play");
} else { // Loadonly
//$('#' + songid).addClass('playing');
$(this).jPlayer("pause", position);
}
if (globals.settings.Debug) {
console.log('[jPlayer Version Info]');
utils.logObjectProperties($(el).data("jPlayer").version);
console.log('[HTML5 Debug Info]');
utils.logObjectProperties($(el).data("jPlayer").html);
console.log('[Flash Debug Info]');
utils.logObjectProperties($(el).data("jPlayer").flash);
console.log('[jPlayer Options Info]');
utils.logObjectProperties($(el).data("jPlayer").options);
load: function(song) {
},
restart: function() {
console.log('restart()');
},
nextTrack: function() {
if((player.currentlyPlayingIndex + 1) < player.queue.length) {
var nextTrack = player.queue[player.currentlyPlayingIndex + 1];
player.currentlyPlayingIndex++;
player.play(nextTrack);
}
},
timeupdate: function (event) {
// Scrobble song once percentage is reached
var p = event.jPlayer.status.currentPercentAbsolute;
if (!scrobbled && p > 30) {
if (globals.settings.Debug) { console.log('LAST.FM SCROBBLE - Percent Played: ' + p); }
internalScrobbleSong(true);
}
},
volumechange: function (event) {
utils.setValue('Volume', event.jPlayer.options.volume, true);
},
ended: function (event) {
if (globals.settings.Repeat) { // Repeat current track if enabled
$(this).jPlayer("play");
} else {
if (!getNextSong()) { // Action if we are at the last song in queue
if (globals.settings.LoopQueue) { // Loop to first track in queue if enabled
var next = $rootScope.queue[0];
this.playSong(false, next);
} else if (globals.settings.AutoPlay) { // Load more tracks if enabled
$rootScope.getRandomSongs('play', '', '');
notifications.updateMessage('Auto Play Activated...', true);
}
} else {
this.nextTrack();
}
}
},
error: function (event) {
var time = $(player1).data("jPlayer").status.currentTime;
$(player1).jPlayer("play", time);
if (globals.settings.Debug) {
console.log("Error Type: " + event.jPlayer.error.type);
console.log("Error Context: " + event.jPlayer.error.context);
console.log("Error Message: " + event.jPlayer.error.message);
console.log("Stream interrupted, retrying from position: " + time);
}
}
});
return;
};
this.playPauseSong = function () {
if (typeof $(player1).data("jPlayer") != 'undefined') {
if ($(player1).data("jPlayer").status.paused) {
$(player1).jPlayer("play");
} else {
$(player1).jPlayer("pause");
previousTrack: function() {
if((player.currentlyPlayingIndex - 1) > 0) {
var previousTrack = player.queue[player.currentlyPlayingIndex - 1];
player.currentlyPlayingIndex--;
player.play(previousTrack);
} else if (player.queue.length > 0) {
player.currentlyPlayingIndex = 0;
player.play(player.queue[player.currentlyPlayingIndex]);
}
}
};
this.playVideo = function (id, bitrate) {
var w, h;
bitrate = parseInt(bitrate);
if (bitrate <= 600) {
w = 320; h = 240;
} else if (bitrate <= 1000) {
w = 480; h = 360;
} else {
w = 640; h = 480;
}
//$("#jPlayerSelector").jPlayer("option", "fullScreen", true);
$("#videodeck").jPlayer({
ready: function () {
/*
$.fancybox({
autoSize: false,
width: w + 10,
height: h + 10,
content: $('#videodeck')
});
*/
$(this).jPlayer("setMedia", {
m4v: 'https://&id=' + id + '&salt=83132'
}).jPlayer("play");
$('#videooverlay').show();
},
swfPath: "js/jplayer",
solution: "html, flash",
supplied: "m4v"
});
};
this.scrobbleSong = internalScrobbleSong;
this.rateSong = function (songid, rating) {
$.ajax({
url: baseURL + '/setRating.view?' + baseParams + '&id=' + songid + "&rating=" + rating,
method: 'GET',
dataType: protocol,
timeout: 10000,
success: function () {
updateMessage('Rating Updated!', true);
}
});
};
// Hyz: have to maintain that in rootScope because I don't yet know how to call it any other way
// from setInterval
$rootScope.saveTrackPosition = this.saveTrackPosition;
}]);
return player;
});

View file

@ -1,20 +1,19 @@
describe("Player service", function() {
'use strict';
var player, $rootScope;
var player;
beforeEach(function() {
module('jamstash.player.service');
inject(function (_player_, _$rootScope_) {
inject(function (_player_) {
player = _player_;
$rootScope = _$rootScope_;
});
});
describe("Given that I have 3 songs in my playing queue", function() {
beforeEach(function() {
$rootScope.queue = [
player.queue = [
{
id: 6726,
name: 'Guarauno',
@ -32,31 +31,34 @@ describe("Player service", function() {
album: 'redux'
}
];
spyOn(player, "playSong").and.stub();
spyOn(player, "restartSong").and.stub();
spyOn(player, "play").and.stub();
});
describe("when I call nextTrack", function() {
it("and no song is playing, it plays the first song", function() {
player.nextTrack();
expect(player.playSong).toHaveBeenCalled();
expect(player.currentlyPlayingIndex).toBe(0);
expect(player.play).toHaveBeenCalledWith(player.queue[0]);
});
it("and the first song is playing, it plays the second song", function() {
$rootScope.queue[0].playing = true;
player.currentlyPlayingIndex = 0;
player.nextTrack();
expect(player.playSong).toHaveBeenCalled();
expect(player.currentlyPlayingIndex).toBe(1);
expect(player.play).toHaveBeenCalledWith(player.queue[1]);
});
it("and the last song is playing, it does nothing", function() {
$rootScope.queue[2].playing = true;
player.currentlyPlayingIndex = 2;
player.nextTrack();
expect(player.playSong).not.toHaveBeenCalled();
expect(player.currentlyPlayingIndex).toBe(2);
expect(player.play).not.toHaveBeenCalled();
});
});
@ -64,24 +66,76 @@ describe("Player service", function() {
it("and no song is playing, it plays the first song", function() {
player.previousTrack();
expect(player.restartSong).toHaveBeenCalled();
expect(player.currentlyPlayingIndex).toBe(0);
expect(player.play).toHaveBeenCalledWith(player.queue[0]);
});
it("and the first song is playing, it restarts the first song", function() {
$rootScope.queue[0].playing = true;
player.currentlyPlayingIndex = 0;
player.previousTrack();
expect(player.restartSong).toHaveBeenCalled();
expect(player.currentlyPlayingIndex).toBe(0);
expect(player.play).toHaveBeenCalledWith(player.queue[0]);
});
it("and the last song is playing, it plays the seconde song", function() {
$rootScope.queue[2].playing = true;
it("and the last song is playing, it plays the second song", function() {
player.currentlyPlayingIndex = 2;
player.previousTrack();
expect(player.playSong).toHaveBeenCalled();
expect(player.currentlyPlayingIndex).toBe(1);
expect(player.play).toHaveBeenCalledWith(player.queue[1]);
});
});
});
describe("Given a song", function() {
var song;
beforeEach(function() {
song = {
id: 6726,
name: 'Guarauno',
artist: 'Carlyn Pollack',
album: 'Arenig',
playing: false
};
});
it("when I play it, the song is marked as playing", function() {
player.play(song);
expect(song.playing).toBeTruthy();
});
it("when I restart playback, the song is still marked as playing", function() {
song.playing = true;
player.restart();
expect(song.playing).toBeTruthy();
});
});
describe("Given that there is no song in my playing queue", function() {
beforeEach(function() {
player.queue = [];
player.currentlyPlayingIndex = -1;
spyOn(player, "play").and.stub();
});
it("when I call nextTrack, it does nothing", function() {
player.nextTrack();
expect(player.play).not.toHaveBeenCalled();
expect(player.currentlyPlayingIndex).toBe(-1);
});
it("when I call previousTrack, it does nothing", function() {
player.previousTrack();
expect(player.play).not.toHaveBeenCalled();
expect(player.currentlyPlayingIndex).toBe(-1);
});
});
});

View file

@ -16,7 +16,7 @@ angular.module('jamstash.player.controller', ['jamstash.player.service', 'jamsta
player.nextTrack();
};
$scope.defaultPlay = function () {
player.defaultPlay();
$scope.play = function () {
player.play();
};
}]);

View file

@ -13,7 +13,7 @@ describe("Player controller", function() {
// Mock the functions of the services
spyOn(player, "nextTrack").and.stub();
spyOn(player, "previousTrack").and.stub();
spyOn(player, "defaultPlay").and.stub();
spyOn(player, "play").and.stub();
$controller('PlayerController', {
$scope: scope,
@ -34,9 +34,9 @@ describe("Player controller", function() {
expect(player.nextTrack).toHaveBeenCalled();
});
it("When I call defaultPlay, it calls defaultPlay in the player service", function() {
scope.defaultPlay();
it("When I call play, it calls play in the player service", function() {
scope.play();
expect(player.defaultPlay).toHaveBeenCalled();
expect(player.play).toHaveBeenCalled();
});
});

View file

@ -8,7 +8,7 @@ angular.module('jamstash.queue.controller', ['jamstash.player.service'])
//angular.copy($rootScope.queue, $scope.song);
$scope.itemType = 'pl';
$scope.playSong = function (loadonly, song) {
player.playSong(loadonly, song);
$scope.playSong = function (song) {
player.play(song);
};
}]);

View file

@ -13,7 +13,7 @@ describe("Queue controller", function() {
player = _player_;
// Mock the functions of the services
spyOn(player, "playSong").and.stub();
spyOn(player, "play").and.stub();
$controller('QueueController', {
$rootScope: $rootScope,
@ -23,11 +23,11 @@ describe("Queue controller", function() {
});
});
});
it("When I call playSong, it calls playSong in the player service", function() {
it("When I call playSong, it calls play in the player service", function() {
var fakeSong = {"id": 3174};
scope.playSong(true, fakeSong);
scope.playSong(fakeSong);
expect(player.playSong).toHaveBeenCalledWith(true, fakeSong);
expect(player.play).toHaveBeenCalledWith(fakeSong);
});
});

View file

@ -318,7 +318,7 @@ angular.module('jamstash.subsonic.service', ['jamstash.settings', 'jamstash.util
$rootScope.queue.push(map.mapSong(item));
});
var next = $rootScope.queue[0];
player.playSong(false, next);
player.play(next);
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
if (typeof data["subsonic-response"].directory.id != 'undefined') {
@ -466,7 +466,7 @@ angular.module('jamstash.subsonic.service', ['jamstash.settings', 'jamstash.util
$rootScope.queue.push(map.mapSong(item));
});
var next = $rootScope.queue[0];
player.playSong(false, next);
player.play(next);
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
content.album = [];
@ -545,7 +545,7 @@ angular.module('jamstash.subsonic.service', ['jamstash.settings', 'jamstash.util
$rootScope.queue.push(map.mapSong(item));
});
var next = $rootScope.queue[0];
player.playSong(false, next);
player.play(next);
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
content.album = [];
@ -775,7 +775,7 @@ angular.module('jamstash.subsonic.service', ['jamstash.settings', 'jamstash.util
}
});
var next = $rootScope.queue[0];
player.playSong(false, next);
player.play(next);
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
content.album = [];

View file

@ -283,7 +283,7 @@ angular.module('jamstash.subsonic.controller', ['jamstash.subsonic.service', 'ja
if(action === 'play') {
$rootScope.queue = [].concat(mappedSongs);
notifications.updateMessage(mappedSongs.length + ' Song(s) Added to Queue', true);
player.playSong(false, $rootScope.queue[0]);
player.play($rootScope.queue[0]);
} else if (action === 'add') {
$rootScope.queue = $rootScope.queue.concat(mappedSongs);
notifications.updateMessage(mappedSongs.length + ' Song(s) Added to Queue', true);
@ -448,8 +448,8 @@ angular.module('jamstash.subsonic.controller', ['jamstash.subsonic.service', 'ja
end = ui.item.index();
$scope.song.splice(end, 0, $scope.song.splice(start, 1)[0]);
};
$scope.playSong = function (loadonly, song) {
player.playSong(loadonly, song);
$scope.playSong = function (song) {
player.play(song);
};
/* Launch on Startup */

View file

@ -23,7 +23,7 @@ describe("Subsonic controller", function() {
return {id: song.id};
});
spyOn(notifications, 'updateMessage').and.stub();
spyOn(player, 'playSong').and.stub();
spyOn(player, 'play').and.stub();
$rootScope.queue = [];
$controller('SubsonicController', {
@ -78,7 +78,7 @@ describe("Subsonic controller", function() {
$rootScope.$apply();
expect(subsonic.getRandomStarredSongs).toHaveBeenCalled();
expect(player.playSong).toHaveBeenCalledWith(false, {id: "2548"});
expect(player.play).toHaveBeenCalledWith({id: "2548"});
expect($rootScope.queue).toEqual([
{id: "2548"}, {id: "8986"}, {id: "2986"}
]);
@ -95,7 +95,7 @@ describe("Subsonic controller", function() {
$rootScope.$apply();
expect(subsonic.getRandomStarredSongs).toHaveBeenCalled();
expect(player.playSong).not.toHaveBeenCalled();
expect(player.play).not.toHaveBeenCalled();
expect($rootScope.queue).toEqual([{id: "7666"}]);
expect(notifications.updateMessage).toHaveBeenCalledWith('No starred songs found on the Subsonic server.', true);
});
@ -157,12 +157,12 @@ describe("Subsonic controller", function() {
});
});
it("When I call playSong, it calls playSong in the player service", function() {
it("When I call playSong, it calls play in the player service", function() {
var fakeSong = {"id": 3572};
scope.playSong(false, fakeSong);
scope.playSong(fakeSong);
expect(player.playSong).toHaveBeenCalledWith(false, fakeSong);
expect(player.play).toHaveBeenCalledWith(fakeSong);
});
//TODO: JMA: all starred