-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
179 lines (143 loc) · 3.83 KB
/
index.html
File metadata and controls
179 lines (143 loc) · 3.83 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html>
<head>
<title>PIWADIO</title>
<meta charset="utf-8">
<meta name="viewport" content="minimal-ui, width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, target-densitydpi=device-dpi" />
<meta name="author" content="David Art [aka] adcomp" >
<link rel="icon" type="image/png" href="static/favicon.png" />
<link href="static/style.css" rel="stylesheet" />
<script type="text/javascript" src="static/jquery.js"></script>
</head>
<body>
<header>
<h1>PI<b>WADIO</b> <small>[ Web Radio Player ]</small></h1>
<h2><small>[ URL . ]</small> <span id="url"></span> </h2>
<div id="nav">
<a id="nav_playlist">Playlist</a> |
<a id="nav_info">Info</a> |
<a id="nav_url">Streaming URL</a>
</div>
</header>
<div class="main">
<div id="inputbox">
<h2>Streaming URL</h2>
<form>
<input id="input_url" type="text"></input>
<br />
<button class="bt_radio" id="play_url">play</button>
</form>
</div>
<div id="info">
<ul>
<li>Name : <span id="info_Name"></span></li>
<li>Genre : <span id="info_Genre"></span></li>
<li>Website : <span id="info_Website"></span></li>
<li>Bitrate : <span id="info_Bitrate"></span></li>
</ul>
</div>
<div id="playlist">loading playlist ...</div>
</div><!-- main -->
<footer class="footer">
<div id="cmd">
<button id="bt_voldown" class="bt_cmd" onclick="send('volume','5%-');">Vol-</button>
<button id="bt_voldown" class="bt_cmd" onclick="send('volume','5%+');">Vol+</button>
<button id="bt_stop" class="bt_cmd" onclick="send('cmd','stop');">Stop</button>
<button id="bt_pause" class="bt_cmd" onclick="send('cmd','pause');">Pause</button>
</div>
</footer>
<script>
// WebSockets obj
var ws = null;
// last data send from server
var data = null;
// radio playlist ( name: url )
var playlist = {};
// when page is loaded, get radio playlist and connect to server
window.onload = init;
function init() {
// hide pause button
$('#bt_pause').hide();
// hide Info / URL
$('#info').hide();
$('#inputbox').hide();
// events
$('#nav_playlist').click(
function() {
$('#playlist').show();
$('#info').hide();
$('#inputbox').hide();
}
);
$('#nav_info').click(
function() {
$('#info').show();
$('#playlist').hide();
$('#inputbox').hide();
}
);
$('#nav_url').click(
function() {
$('#inputbox').show();
$('#info').hide();
$('#playlist').hide();
}
);
// get radio playlist from json file
$.getJSON( "static/playlist.json", function( data ) {
var radios = [];
// for each key, add a button
$.each( data, function( key, val ) {
playlist[key] = val;
html = '<div class="radio">';
html += '<button class="bt_radio" onclick="playRadio(\'' + key + '\');">';
html += key;
html += '</button></div>';
radios.push( html );
});
$("#playlist").html(radios.join( "" ));
});
// get the full url
var url = window.location.href;
var arr = url.split('/');
// grab the host
var host = arr[2];
// WebSocket server connection
connect(host);
}
function connect(host) {
// connect to server
ws = new WebSocket("ws://" + host + "/piwardio");
ws.onmessage = function(evt) {
// data is json format
data = JSON.parse(evt.data);
if (data.state == "stop") {
$('#bt_pause').hide();
}
else if (data.state == "play" || data.state == "pause") {
$('#bt_pause').show();
}
$('#url').html(data.url);
for (var key in data.info) {
$('#info_'+key).html(data.info[key]);
}
};
ws.onclose = function(evt) {
console.log("Connection close ..");
};
ws.onopen = function(evt) {
console.log("WebSocket open ..")
};
}
function playRadio(name) {
cmd = JSON.stringify({"cmd": "loadlist", "url": playlist[name]});
ws.send(cmd);
}
function send(key, value) {
obj = {};
obj[key] = value;
ws.send(JSON.stringify(obj));
}
</script>
</body>
</html>