Web remote controls

I can play, pause, stop, and advance to the next song through the web
interface.
This commit is contained in:
Bryan Schumaker 2010-11-19 22:47:41 -05:00
parent acecb18120
commit a88f8225a7
10 changed files with 102 additions and 9 deletions

View File

@ -30,7 +30,10 @@ def body(wfile, args):
img_ar = artist.replace("/", "%2F")
img_al = album.replace("/", "%2F")
wfile.write("<tr><td><table align=center width=100%><tr>")
wfile.write("<td align=center><img src=\"artwork/%s/%s.jpg\" height=192/></td>" % (img_ar, img_al))
wfile.write("<td align=center><table align=center width=100%>")
wfile.write("<tr><td align=center>")
wfile.write("<img src=\"artwork/%s/%s.jpg\" height=192/></td></tr>" % (img_ar, img_al))
wfile.write("<tr><td align=center id=\"audio\"></td></tr></table>")
wfile.write("<td align><table align=left>\n")
titles = []
@ -46,11 +49,6 @@ def body(wfile, args):
wfile.write("</table></td>")
wfile.write("</tr></table></td></tr>")
wfile.write("<tr><td id=\"audio\">")
#wfile.write("<audio src=\"140401.ogg\" autoplay controls/>")
#wfile.write("Text when no audio")
wfile.write("</td></tr>")
wfile.write("</table>")

71
html/controls.html Normal file
View File

@ -0,0 +1,71 @@
<html>
<head>
<script type="text/javascript">
function do_request(action)
{
var http = new XMLHttpRequest();
http.open('GET', "controls.py?a="+action, true);
http.send();
return http;
}
/*function get_response(http)
{
while (http.readyState != 4)
{}
var resp = http.responseText;
return resp;
}*/
function control(action)
{
var http = do_request(action);
/*var resp = get_response(http);*/
}
function play()
{
control("play");
var button = document.getElementById("play_pause");
button.innerHTML = "<img src=\"stock_media-pause.png\" onclick=\"pause();\">";
}
function pause()
{
control("pause");
var button = document.getElementById("play_pause");
button.innerHTML = "<img src=\"stock_media-play.png\" onclick=\"play();\">";
}
function stop()
{
control("stop");
var button = document.getElementById("play_pause");
button.innerHTML = "<img src=\"stock_media-play.png\" onclick=\"play();\">";
}
function next()
{
control("next");
}
</script>
</head>
<body>
<table>
<tr>
<td id="play_pause">
<img src="stock_media-play.png" onclick="play();"/>
</td><td>
<img src="stock_media-stop.png" onclick="stop();"/>
</td><td>
<img src="stock_media-next.png" onclick="next();"/>
</td>
</tr>
</table>
</body>
</html>

23
html/controls.py Normal file
View File

@ -0,0 +1,23 @@
# Bryan Schumaker (11/18/2010)
import libsaria.audio
import libsaria.sources
play = libsaria.audio.play
pause = libsaria.audio.pause
stop = libsaria.audio.stop
next = libsaria.sources.plist_next
def to_html(wfile, args):
action = args["a"]
ret = False
if action == "play":
ret = play()
elif action == "pause":
ret = pause()
elif action == "stop":
ret = stop()
elif action == "next":
ret = next()
wfile.write(str(ret))

View File

@ -12,6 +12,7 @@ function message()
<body>
<!--<a id="bryan" onclick="message();">Text</a>-->
<a href="library.py">Library Browser</a>
<a href="controls.html">Remote Controls</a>
</body>
</html>

BIN
html/stock_media-next.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
html/stock_media-pause.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 875 B

BIN
html/stock_media-play.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
html/stock_media-stop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 837 B

View File

@ -111,7 +111,7 @@ def rand_next():
return id
def next():
if libsaria.prefs2.get_pref("libsaria.random") == True:
if libsaria.prefs.get_pref("libsaria.random") == True:
id = rand_next()
else:
id = seq_next()

View File

@ -19,8 +19,8 @@ html = join(path.cwd(), "html")
server = None
types = {".html":"text/html", ".js":"text/javascript",
".ico":"image/vnd.microsoft.icon",
".py":"text/html", ".jpg":"image/jpeg",
".mp3":"audio/mpeg",
".png":"image/png", ".jpg":"image/jpeg",
".py":"text/html", ".mp3":"audio/mpeg",
".ogg":"audio/ogg"}