diff options
author | montellese <montellese@xbmc.org> | 2011-09-04 18:40:10 +0200 |
---|---|---|
committer | montellese <montellese@xbmc.org> | 2011-09-18 18:54:53 +0200 |
commit | 054c5dbb4116f6326bf0f21c23cff847df2454f9 (patch) | |
tree | d397ac94b11361ed63bc08399de12e6319c11efb /addons | |
parent | c4f161e177f5e079f2ba67c264c2ebb85a9a2b03 (diff) |
update webinterface to use latest jsonrpc changes
Diffstat (limited to 'addons')
-rwxr-xr-x | addons/webinterface.default/css/core.css | 2 | ||||
-rwxr-xr-x | addons/webinterface.default/js/MediaLibrary.js | 196 | ||||
-rwxr-xr-x | addons/webinterface.default/js/NowPlayingManager.js | 162 |
3 files changed, 178 insertions, 182 deletions
diff --git a/addons/webinterface.default/css/core.css b/addons/webinterface.default/css/core.css index 5a85857dd5..627f85d5c2 100755 --- a/addons/webinterface.default/css/core.css +++ b/addons/webinterface.default/css/core.css @@ -567,7 +567,7 @@ div.imgWrapper div.inner { #nowPlayingPlaylist, #nextTrack { width: 416px; - float: right; + float: left; cursor: pointer; z-index: 1000; } diff --git a/addons/webinterface.default/js/MediaLibrary.js b/addons/webinterface.default/js/MediaLibrary.js index d1732571a5..46d5c5b7ac 100755 --- a/addons/webinterface.default/js/MediaLibrary.js +++ b/addons/webinterface.default/js/MediaLibrary.js @@ -25,9 +25,11 @@ var MediaLibrary = function() { } MediaLibrary.prototype = { - + playlists: { }, + init: function() { - this.bindControls(); + this.bindControls(); + this.getPlaylists(); }, bindControls: function() { @@ -64,6 +66,25 @@ MediaLibrary.prototype = { return result; }, + getPlaylists: function() { + jQuery.ajax({ + type: 'POST', + url: JSON_RPC + '?GetPlaylists', + data: '{"jsonrpc": "2.0", "method": "Playlist.GetPlaylists", "id": 1}', + timeout: 3000, + success: jQuery.proxy(function(data) { + if (data && data.result && data.result.length > 0) { + $.each($(data.result), jQuery.proxy(function(i, item) { + this.playlists[item.type] = item.playlistid; + }, this)); + } + }, this), + error: jQuery.proxy(function(data, error) { + displayCommunicationError(); + setTimeout(jQuery.proxy(this.updateState, this), 2000); + }, this), + dataType: 'json'}); + }, remoteControlOpen: function(event) { this.resetPage(); $('#remoteControl').addClass('selected'); @@ -122,15 +143,13 @@ MediaLibrary.prototype = { pressRemoteKey: function(event) { var keyPressed=event.data.key; $('#spinner').show(); - var player='other'; + var player = -1; + // TODO: Get active player if($('#videoDescription').is(':visible')) - { - player='video' - } + player = this.playlists["video"]; else if($('#audioDescription').is(':visible')) - { - player='audio' - } + player = this.playlists["audio"]; + //common part switch(keyPressed) { case 'cleanlib_a': @@ -152,24 +171,24 @@ MediaLibrary.prototype = { jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Input.Home", "id": 1}', function(data){$('#spinner').hide();}, 'json'); return; case 'mute': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "XBMC.ToggleMute", "id": 1}', function(data){$('#spinner').hide();}, 'json'); + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Application.ToggleMute", "id": 1}', function(data){$('#spinner').hide();}, 'json'); return; case 'power': jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "System.Shutdown", "id": 1}', function(data){$('#spinner').hide();}, 'json'); return; case 'volumeup': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "XBMC.GetVolume", "id": 1}', function(data){ - var volume=data.result + 1; - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "XBMC.SetVolume", "params": {"value": '+volume+'},"id": 1}', function(data){ + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Application.GetProperties", "params": { "properties": [ "volume" ] }, "id": 1}', function(data){ + var volume = data.result.volume + 1; + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "value": '+volume+' }, "id": 1}', function(data){ $('#spinner').hide(); }, 'json'); }, 'json'); return; case 'volumedown': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "XBMC.GetVolume", "id": 1}', function(data){ - var volume=data.result - 1; - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "XBMC.SetVolume", "params": {"value": '+volume+'},"id": 1}', function(data){ + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Application.GetProperties", "params": { "properties": [ "volume" ] }, "id": 1}', function(data){ + var volume = data.result.volume - 1; + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "value": '+volume+' }, "id": 1}', function(data){ $('#spinner').hide(); }, 'json'); @@ -177,112 +196,62 @@ MediaLibrary.prototype = { return; } //menus or other sections - if(player=='other') + if (player == -1) { switch(keyPressed) { - case 'up': jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Input.Up", "id": 1}', function(data){$('#spinner').hide();}, 'json'); return; case 'down': jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Input.Down", "id": 1}', function(data){$('#spinner').hide();}, 'json'); return; - case 'left': jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Input.Left", "id": 1}', function(data){$('#spinner').hide();}, 'json'); return; - case 'right': jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Input.Right", "id": 1}', function(data){$('#spinner').hide();}, 'json'); return; - case 'ok': jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Input.Select", "id": 1}', function(data){$('#spinner').hide();}, 'json'); return; } } - //videoplaying - if(player=='video') - { - switch(keyPressed) { - - - case 'up': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "VideoPlayer.BigSkipForward", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'down': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "VideoPlayer.BigSkipBackward", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - - case 'left': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "VideoPlayer.SmallSkipBackward", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - - case 'right': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "VideoPlayer.SmallSkipForward", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'playpause': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "VideoPlayer.PlayPause", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'stop': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "VideoPlayer.Stop", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'next': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "VideoPlayer.SkipNext", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'previous': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "VideoPlayer.SkipPrevious", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'forward': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "VideoPlayer.Forward", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'rewind': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "VideoPlayer.Rewind", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - - } - } - if(player=='audio') - { - switch(keyPressed) { - - - case 'up': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "AudioPlayer.BigSkipForward", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'down': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "AudioPlayer.BigSkipBackward", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - - case 'left': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "AudioPlayer.SmallSkipBackward", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - - case 'right': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "AudioPlayer.SmallSkipForward", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'playpause': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "AudioPlayer.PlayPause", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'stop': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "AudioPlayer.Stop", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'next': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "AudioPlayer.SkipNext", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'previous': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "AudioPlayer.SkipPrevious", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'forward': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "AudioPlayer.Forward", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - case 'rewind': - jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "AudioPlayer.Rewind", "id": 1}', function(data){$('#spinner').hide();}, 'json'); - return; - - } - } - + + if (player >= 0) + { + switch(keyPressed) { + case 'up': + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Player.BigSkipForward", "params": { "playerid": ' + player + ' }, "id": 1}', function(data){$('#spinner').hide();}, 'json'); + return; + case 'down': + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Player.BigSkipBackward", "params": { "playerid": ' + player + ' }, "id": 1}', function(data){$('#spinner').hide();}, 'json'); + return; + case 'left': + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Player.SmallSkipBackward", "params": { "playerid": ' + player + ' }, "id": 1}', function(data){$('#spinner').hide();}, 'json'); + return; + case 'right': + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Player.SmallSkipForward", "params": { "playerid": ' + player + ' }, "id": 1}', function(data){$('#spinner').hide();}, 'json'); + return; + case 'playpause': + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Player.PlayPause", "params": { "playerid": ' + player + ' }, "id": 1}', function(data){$('#spinner').hide();}, 'json'); + return; + case 'stop': + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Player.Stop", "params": { "playerid": ' + player + ' }, "id": 1}', function(data){$('#spinner').hide();}, 'json'); + return; + case 'next': + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Player.SkipNext", "params": { "playerid": ' + player + ' }, "id": 1}', function(data){$('#spinner').hide();}, 'json'); + return; + case 'previous': + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Player.SkipPrevious", "params": { "playerid": ' + player + ' }, "id": 1}', function(data){$('#spinner').hide();}, 'json'); + return; + case 'forward': + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Player.Forward", "params": { "playerid": ' + player + ' }, "id": 1}', function(data){$('#spinner').hide();}, 'json'); + return; + case 'rewind': + jQuery.post(JSON_RPC + '?SendRemoteKey', '{"jsonrpc": "2.0", "method": "Player.Rewind", "params": { "playerid": ' + player + ' }, "id": 1}', function(data){$('#spinner').hide();}, 'json'); + return; + } + } }, musicLibraryOpen: function(event) { @@ -635,13 +604,9 @@ MediaLibrary.prototype = { }, playTVShow: function(event) { - jQuery.post(JSON_RPC + '?ClearPlaylist', '{"jsonrpc": "2.0", "method": "VideoPlaylist.Clear", "id": 1}', jQuery.proxy(function(data) { - //check that clear worked. - jQuery.post(JSON_RPC + '?AddTvShowToPlaylist', '{"jsonrpc": "2.0", "method": "VideoPlaylist.Add", "params": { "item": { "episodeid": ' + event.data.episode.episodeid + ' } }, "id": 1}', jQuery.proxy(function(data) { - //play specific song in playlist - jQuery.post(JSON_RPC + '?PlaylistItemPlay', '{"jsonrpc": "2.0", "method": "VideoPlaylist.Play", "params": { "item": 0 }, "id": 1}', function(data) {this.hideOverlay();}, 'json'); - }, this), 'json'); - }, this), 'json'); + jQuery.post(JSON_RPC + '?AddTvShowToPlaylist', '{"jsonrpc": "2.0", "method": "Player.Play", "params": { "item": { "episodeid": ' + event.data.episode.episodeid + ' } }, "id": 1}', jQuery.proxy(function(data) { + this.hideOverlay(); + }, this), 'json'); }, hideOverlay: function(event) { if (this.activeCover) { @@ -672,8 +637,7 @@ MediaLibrary.prototype = { } }, playMovie: function(event) { - var file = this.replaceAll(event.data.movie.file, "\\", "\\\\"); - jQuery.post(JSON_RPC + '?PlayMovie', '{"jsonrpc": "2.0", "method": "XBMC.Play", "params": { "file": "' + file + '" }, "id": 1}', jQuery.proxy(function(data) { + jQuery.post(JSON_RPC + '?PlayMovie', '{"jsonrpc": "2.0", "method": "Player.Play", "params": { "item": { "movieid": ' + event.data.movie.movieid + ' } }, "id": 1}', jQuery.proxy(function(data) { this.hideOverlay(); }, this), 'json'); }, @@ -707,11 +671,11 @@ MediaLibrary.prototype = { this.updatePlayButtonLocation(); }, playTrack: function(event) { - jQuery.post(JSON_RPC + '?ClearPlaylist', '{"jsonrpc": "2.0", "method": "AudioPlaylist.Clear", "id": 1}', jQuery.proxy(function(data) { + jQuery.post(JSON_RPC + '?ClearPlaylist', '{"jsonrpc": "2.0", "method": "Playlist.Clear", "params": { "playlistid": ' + this.playlists["audio"] + ' }, "id": 1}', jQuery.proxy(function(data) { //check that clear worked. - jQuery.post(JSON_RPC + '?AddAlbumToPlaylist', '{"jsonrpc": "2.0", "method": "AudioPlaylist.Add", "params": { "item": { "albumid": ' + event.data.album.albumid + ' } }, "id": 1}', jQuery.proxy(function(data) { + jQuery.post(JSON_RPC + '?AddAlbumToPlaylist', '{"jsonrpc": "2.0", "method": "Playlist.Add", "params": { "playlistid": ' + this.playlists["audio"] + ', "item": { "albumid": ' + event.data.album.albumid + ' } }, "id": 1}', jQuery.proxy(function(data) { //play specific song in playlist - jQuery.post(JSON_RPC + '?PlaylistItemPlay', '{"jsonrpc": "2.0", "method": "AudioPlaylist.Play", "params": { "item": '+ event.data.itmnbr + ' }, "id": 1}', function() {}, 'json'); + jQuery.post(JSON_RPC + '?PlaylistItemPlay', '{"jsonrpc": "2.0", "method": "Player.Play", "params": { "playlist": { "playlistid": ' + this.playlists["audio"] + ', "position": '+ event.data.itmnbr + ' } }, "id": 1}', function() {}, 'json'); }, this), 'json'); }, this), 'json'); }, @@ -818,7 +782,7 @@ MediaLibrary.prototype = { } }, startSlideshow: function(event) { - jQuery.post(JSON_RPC + '?StartSlideshow', '{"jsonrpc": "2.0", "method": "XBMC.StartSlideshow", "params": { "recursive" : "true", "random":"true", "directory" : "' + this.replaceAll(event.data.directory.file, "\\", "\\\\") + '" }, "id": 1}', null, 'json'); + jQuery.post(JSON_RPC + '?StartSlideshow', '{"jsonrpc": "2.0", "method": "Player.Play", "params": { "slideshow": { "recursive" : "true", "random":"true", "directory" : "' + this.replaceAll(event.data.directory.file, "\\", "\\\\") + '" } }, "id": 1}', null, 'json'); }, showDirectory: function(event) { var directory = event.data.directory.file; diff --git a/addons/webinterface.default/js/NowPlayingManager.js b/addons/webinterface.default/js/NowPlayingManager.js index 35b22b6926..2269c0b989 100755 --- a/addons/webinterface.default/js/NowPlayingManager.js +++ b/addons/webinterface.default/js/NowPlayingManager.js @@ -26,6 +26,13 @@ var NowPlayingManager = function() { NowPlayingManager.prototype = { updateCounter: 0, + activePlayer: "", + activePlayerId: -1, + currentItem: -1, + playing: false, + paused: false, + playlistid: -1, + init: function() { $('#pbPause').hide(); /* Assume we are not playing something */ this.bindPlaybackControls(); @@ -41,26 +48,48 @@ NowPlayingManager.prototype = { data: '{"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1}', timeout: 3000, success: jQuery.proxy(function(data) { - if (data && data.result) { - if (data.result.audio && this.activePlayer != 'Audio') { - this.activePlayer = 'Audio'; - this.stopVideoPlaylistUpdate(); - this.displayAudioNowPlaying(); - this.showFooter(); - this.stopRefreshTime(); - } else if (data.result.video && this.activePlayer != 'Video') { - this.activePlayer = 'Video'; - this.stopAudioPlaylistUpdate(); - this.displayVideoNowPlaying(); - this.showFooter(); - this.stopRefreshTime(); - } else if (data.result.video || data.result.audio) { - this.showFooter(); - } else if (!data.result.audio && !data.result.video) { + if (data && data.result && data.result.length > 0) { + if (data.result[0].playerid != this.activePlayerId) { + this.activePlayerId = data.result[0].playerid; + this.activePlayer = data.result[0].type; + if (this.activePlayer == "audio") + { + this.stopVideoPlaylistUpdate(); + this.displayAudioNowPlaying(); + } + else if (this.activePlayer == "video") + { + this.stopAudioPlaylistUpdate(); + this.displayVideoNowPlaying(); + } + else + { + this.stopVideoPlaylistUpdate(); + this.stopAudioPlaylistUpdate(); + this.activePlayer = ""; + this.activePlayerId = -1; + } + this.stopRefreshTime(); - this.hideFooter(); - } + + this.updatePlayer(); + } } + else if (data.result.length <= 0) + { + this.stopVideoPlaylistUpdate(); + this.stopAudioPlaylistUpdate(); + this.activePlayer = ""; + this.activePlayerId = -1; + } + + if (this.activePlayerId >= 0) + this.showFooter(); + else { + this.stopRefreshTime(); + this.hideFooter(); + } + setTimeout(jQuery.proxy(this.updateState, this), 1000); }, this), error: jQuery.proxy(function(data, error) { @@ -69,6 +98,34 @@ NowPlayingManager.prototype = { }, this), dataType: 'json'}); }, + updatePlayer: function() { + jQuery.post(JSON_RPC + '?UpdatePlayer', + '{"jsonrpc": "2.0", "method": "Player.GetProperties", "params": { "playerid": ' + this.activePlayerId + ', "properties": [ "playlistid", "speed", "position", "totaltime", "time" ] }, "id": 1}', + jQuery.proxy(function(data) { + if (data && data.result) + { + this.playlistid = data.result.playlistid; + this.playing = data.result.speed != 0; + this.paused = data.result.speed == 0; + this.currentItem = data.result.position; + this.trackBaseTime = timeToDuration(data.result.time); + this.trackDurationTime = timeToDuration(data.result.totaltime); + if (!this.autoRefreshAudioData && !this.autoRefreshVideoData && this.playing) { + if (this.activePlayer == 'audio') { + this.autoRefreshAudioData = true; + this.refreshAudioData(); + } else if (this.activePlayer == 'video') { + this.autoRefreshVideoData = true; + this.refreshVideoData(); + } + } + } + if ((this.autoRefreshAudioData || this.autoRefreshVideoData) && !this.activeItemTimer) { + this.activeItemTimer = 1; + setTimeout(jQuery.proxy(this.updateActiveItemDurationLoop, this), 1000); + } + }, this), 'json'); + }, bindPlaybackControls: function() { $('#pbNext').bind('click', jQuery.proxy(this.nextTrack, this)); $('#pbPrev').bind('click', jQuery.proxy(this.prevTrack, this)); @@ -96,7 +153,7 @@ NowPlayingManager.prototype = { }, nextTrack: function() { if (this.activePlayer) { - jQuery.post(JSON_RPC + '?SkipNext', '{"jsonrpc": "2.0", "method": "' + this.activePlayer + 'Player.SkipNext", "id": 1}', jQuery.proxy(function(data) { + jQuery.post(JSON_RPC + '?SkipNext', '{"jsonrpc": "2.0", "method": "Player.GoNext", "params": { "playerid": ' + this.activePlayerId + ' }, "id": 1}', jQuery.proxy(function(data) { if (data && data.result == 'OK') { //this.updateAudioPlaylist(true); } @@ -105,7 +162,7 @@ NowPlayingManager.prototype = { }, prevTrack: function() { if (this.activePlayer) { - jQuery.post(JSON_RPC + '?SkipPrevious', '{"jsonrpc": "2.0", "method": "' + this.activePlayer + 'Player.SkipPrevious", "id": 1}', jQuery.proxy(function(data) { + jQuery.post(JSON_RPC + '?SkipPrevious', '{"jsonrpc": "2.0", "method": "Player.GoPrevious", "params": { "playerid": ' + this.activePlayerId + ' }, "id": 1}', jQuery.proxy(function(data) { if (data && data.result == 'OK') { //this.updateAudioPlaylist(true); } @@ -114,7 +171,7 @@ NowPlayingManager.prototype = { }, stopTrack: function() { if (this.activePlayer) { - jQuery.post(JSON_RPC + '?Stop', '{"jsonrpc": "2.0", "method": "' + this.activePlayer + 'Player.Stop", "id": 1}', jQuery.proxy(function(data) { + jQuery.post(JSON_RPC + '?Stop', '{"jsonrpc": "2.0", "method": "Player.Stop", "params": { "playerid": ' + this.activePlayerId + ' }, "id": 1}', jQuery.proxy(function(data) { if (data && data.result == 'OK') { this.playing = false; this.paused = false; @@ -127,11 +184,11 @@ NowPlayingManager.prototype = { }, playPauseTrack: function() { if (this.activePlayer) { - var method = this.activePlayer + ((this.playing || this.paused) ? 'Player.PlayPause' : 'Playlist.Play'); - jQuery.post(JSON_RPC + '?PlayPause', '{"jsonrpc": "2.0", "method": "' + method + '", "id": 1}', jQuery.proxy(function(data) { + var method = ((this.playing || this.paused) ? 'Player.PlayPause' : 'Playlist.Play'); + jQuery.post(JSON_RPC + '?PlayPause', '{"jsonrpc": "2.0", "method": "' + method + '", "params": { "playerid": ' + this.activePlayerId + ' }, "id": 1}', jQuery.proxy(function(data) { if (data && data.result) { - this.playing = data.result.playing; - this.paused = data.result.paused; + this.playing = data.result.speed != 0; + this.paused = data.result.speed == 0; if (this.playing) { this.showPauseButton(); } else { @@ -164,7 +221,7 @@ NowPlayingManager.prototype = { playPlaylistItem: function(sender) { var sequenceId = $(sender.currentTarget).attr('seq'); if (!this.activePlaylistItem || (this.activePlaylistItem !== undefined && sequenceId != this.activePlaylistItem.seq)) { - jQuery.post(JSON_RPC + '?PlaylistItemPlay', '{"jsonrpc": "2.0", "method": "' + this.activePlayer + 'Playlist.Play", "params": { "item": ' + sequenceId + '}, "id": 1}', function() {}, 'json'); + jQuery.post(JSON_RPC + '?PlaylistItemPlay', '{"jsonrpc": "2.0", "method": "Player.GoTo", "params": { "playerid": ' + this.activePlayerId + ', "item": ' + sequenceId + '}, "id": 1}', function() {}, 'json'); } this.hidePlaylist(); }, @@ -188,23 +245,23 @@ NowPlayingManager.prototype = { updateAudioPlaylist: function() { jQuery.ajax({ type: 'POST', - url: JSON_RPC + '?updateAudioPlaylist', - data: '{"jsonrpc": "2.0", "method": "AudioPlaylist.GetItems", "params": { "fields": ["title", "album", "artist", "duration"] }, "id": 1}', + url: JSON_RPC + '?updateAudioPlaylist', + data: '{"jsonrpc": "2.0", "method": "Playlist.GetItems", "params": { "playlistid": ' + this.playlistid + ', "fields": [ "title", "album", "artist", "duration", "thumbnail" ] }, "id": 1}', success: jQuery.proxy(function(data) { - if (data && data.result && data.result.items && data.result.limits.total > 0) { + if (data && data.result && data.result.items && data.result.items.length > 0 && data.result.limits.total > 0) { //Compare new playlist to active playlist, only redraw if a change is noticed - if (!this.activePlaylistItem || this.playlistChanged(data.result.items) || (this.activePlaylistItem && (this.activePlaylistItem.seq != data.result.state.current))) { + if (!this.activePlaylistItem || this.playlistChanged(data.result.items) || (this.activePlaylistItem && (this.activePlaylistItem.seq != this.currentItem))) { var ul = $('<ul>'); var activeItem; $.each($(data.result.items), jQuery.proxy(function(i, item) { var li = $('<li>'); var code = '<span class="duration">' + durationToString(item.duration) + '</span><div class="trackInfo" title="' + item.title + ' - ' + item.artist + '"><span class="trackTitle">' + item.title + '</span> - <span class="trackArtist">' + item.artist + '</span></div>'; - if (i == data.result.state.current) { + if (i == this.currentItem) { activeItem = item; activeItem.seq = i; li.addClass('activeItem'); } - if (i == (data.result.state.current + 1)) { + if (i == (this.currentItem + 1)) { $('#nextTrack').html(code).show(); } li.bind('click', jQuery.proxy(this.playPlaylistItem, this)); @@ -225,7 +282,7 @@ NowPlayingManager.prototype = { this.activePlaylistItem = activeItem; if (!this.updateActiveItemDurationRunOnce) { this.updateActiveItemDurationRunOnce = true; - this.updateActiveItemDuration(); + this.updatePlayer(); } } else if (!activeItem) { this.stopRefreshTime(); @@ -263,32 +320,7 @@ NowPlayingManager.prototype = { }, updateActiveItemDurationLoop: function() { this.activeItemTimer = 0; - this.updateActiveItemDuration(); - }, - updateActiveItemDuration: function() { - jQuery.post(JSON_RPC + '?updateDuration', '{"jsonrpc": "2.0", "method": "' + this.activePlayer + 'Player.GetTime", "id": 1}', jQuery.proxy(function(data) { - if (data && data.result) { - this.trackBaseTime = timeToDuration(data.result.time); - this.trackDurationTime = timeToDuration(data.result.total); - this.playing = data.result.playing; - this.paused = data.result.paused; - if (!this.autoRefreshAudioData && !this.autoRefreshVideoData) { - if (data.result.playing) { - if (this.activePlayer == 'Audio') { - this.autoRefreshAudioData = true; - this.refreshAudioData(); - } else if (this.activePlayer == 'Video') { - this.autoRefreshVideoData = true; - this.refreshVideoData(); - } - } - } - } - if ((this.autoRefreshAudioData || this.autoRefreshVideoData) && !this.activeItemTimer) { - this.activeItemTimer = 1; - setTimeout(jQuery.proxy(this.updateActiveItemDurationLoop, this), 1000); - } - }, this), 'json'); + this.updatePlayer(); }, refreshAudioDataLoop: function() { this.audioRefreshTimer = 0; @@ -420,10 +452,10 @@ NowPlayingManager.prototype = { updateVideoPlaylist: function() { jQuery.ajax({ type: 'POST', - url: JSON_RPC + '?updateVideoPlaylist', - data: '{"jsonrpc": "2.0", "method": "VideoPlaylist.GetItems", "params": { "fields": ["title", "season", "episode", "plot", "runtime", "showtitle","thumbnail"] }, "id": 1}', + url: JSON_RPC + '?updateVideoPlaylist', + data: '{"jsonrpc": "2.0", "method": "Playlist.GetItems", "params": { "playlistid": ' + this.playlistid + ', "fields": ["title", "season", "episode", "plot", "runtime", "showtitle","thumbnail"] }, "id": 1}', success: jQuery.proxy(function(data) { - if (data && data.result && data.result.items && data.result.limits.total > 0) { + if (data && data.result && data.result.items && data.result.items.length > 0 && data.result.limits.total > 0) { //Compare new playlist to active playlist, only redraw if a change is noticed. if (this.playlistChanged(data.result.items)) { var ul = $('<ul>'); @@ -435,12 +467,12 @@ NowPlayingManager.prototype = { extra = item.season + 'x' + item.episode + ' '; } var code = '<span class="duration">' + durationToString(item.runtime) + '</span><div class="trackInfo" title="' + extra + item.title + '"><span class="trackTitle">' + extra + item.title + '</span></div>'; - if (i == data.result.state.current) { + if (i == this.currentItem) { activeItem = item; activeItem.seq = i; li.addClass('activeItem'); } - if (i == (data.result.state.current + 1)) { + if (i == (this.currentItem + 1)) { $('#nextTrack').html(code).show(); } li.bind('click', jQuery.proxy(this.playPlaylistItem, this)); @@ -461,7 +493,7 @@ NowPlayingManager.prototype = { this.activePlaylistItem = activeItem; if (!this.updateActiveItemDurationRunOnce) { this.updateActiveItemDurationRunOnce = true; - this.updateActiveItemDuration(); + this.updatePlayer(); } } else if (!activeItem) { this.stopRefreshTime(); |