aboutsummaryrefslogtreecommitdiff
path: root/web/poc_jsonrpc/nowplaying.html
blob: a1a3213d0790fb8e30d3a45dce5be37ddb500bf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<html>
<head>
<title>XBMC - Now playing</title>
<link type="text/css" rel="stylesheet" href="basic.css">
<script type="text/javascript" src="json.js"></script>
<script type="text/javascript">
function CallMethod(method)
{
  var http_request = new XMLHttpRequest();
  http_request.open( "POST", "/jsonrpc", false );
  http_request.send('{"jsonrpc": "2.0", "method": "' + method + '", "params": { "fields": ["title", "plot"] }, "id": 1}');
  window.location.reload( false );
}

function CallPlay(player, playlistItem)
{
  var http_request = new XMLHttpRequest();
  http_request.open( "POST", "/jsonrpc", false );
  http_request.send('{"jsonrpc": "2.0", "method": "' + player + 'Playlist.Play", "params": ' + playlistItem + ', "id": 1}');
}

function refresh()
{
  window.location.reload( false );
}
</script>

</head>
<body>
<table class="Navigation">
<tr class="primary">
  <td class="selected"><a href="nowplaying.html">Now playing</a></td>
  <td class="unselected"><a href="movies.html">Videos</a></td>
  <td class="unselected"><a href="artists.html">Music</a></td>
  <td class="unselected"><a href="development.html">Development</a></td>
</tr>
</table>
<br>

<script type="text/javascript">
setTimeout( "refresh()", 5*1000 );
var http_request = new XMLHttpRequest();
http_request.open( "POST", "/jsonrpc", false );
http_request.send('{"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1}');

var players = JSON.parse(http_request.responseText)["result"];
if (players["video"] || players["audio"]) {
  var player = "Video";
  if (players["audio"])
    player = "Audio";

  http_request = new XMLHttpRequest();
  http_request.open( "POST", "/jsonrpc", false );
  http_request.send('{"jsonrpc": "2.0", "method": "' + player + 'Playlist.GetItems", "params": { "fields": ["title", "plot"] }, "id": 1}');

  var the_object = JSON.parse(http_request.responseText);
  var result = the_object["result"];
  var activeItem = result["current"];
  var array = result["items"];

  if (activeItem >= 0) {
    var imgSrc = array[activeItem]["thumbnail"] ? ('/vfs/' + escape(array[activeItem]["thumbnail"])) : "images/DefaultAlbumCover.png";
    document.write('<img src="' + imgSrc + '"></img>');

    document.write('<br></br>');

    document.write('<a href="nowplaying.html" onclick=CallMethod("' + player + 'Player.SkipPrevious")><img src="images/OSDPrevTrackFO.png"></img></a>');
    document.write('<a href="nowplaying.html" onclick=CallMethod("' + player + 'Player.Stop")><img src="images/OSDStopFO.png"></img></a>');
    document.write('<a href="nowplaying.html" onclick=CallMethod("' + player + 'Player.PlayPause")><img src="images/OSDPlayFO.png"></img></a>');
    document.write('<a href="nowplaying.html" onclick=CallMethod("' + player + 'Player.SkipNext")><img src="images/OSDNextTrackFO.png"></img></a>');

    document.write('<br></br>');

    document.write('<table class="Playlist"><tbody>');
    for (var i in array) {
      var item = array[i];

      document.write('<tr class="' + (i % 2 == 0 ? "even" : "odd") + '">');
      document.write('<td class="label"><a href="nowplaying.html" onclick=CallPlay("' + player + '",' + i + ')>' + item["label"] + '</a></td>');
      if (i == activeItem)
        document.write('<td class="playing"><img src="images/play.png" height=16></img></td>');
      else
        document.write('<td class="playing"></td>');
      document.write('</tr>');
    }
    document.write('</tbody></table>');
  }
} else {
  document.write("Nothings playing");
}
</script>
</body>
</html>