sonos

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit a68900a8bb341244e680e2a0764f699f4b158184
parent 3bc003d1c2e96b4ef3c292fbec94ce3bce339b6b
Author: Brian Swetland <swetland@frotz.net>
Date:   Sun,  7 Aug 2011 09:56:06 -0700

Sonos: add item flags and wire up getVolume

Diffstat:
Mnet/frotz/sonos/Sonos.java | 21+++++++++++++++++++--
Mnet/frotz/sonos/SonosItem.java | 4++++
Mnet/frotz/sonos/app.java | 12+++++++-----
3 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/net/frotz/sonos/Sonos.java b/net/frotz/sonos/Sonos.java @@ -74,11 +74,23 @@ public class Sonos { } /* volume controls */ - public void volume() { + public int volume() { + int n; rpc.prepare(render,"GetVolume"); rpc.simpleTag("InstanceID",0); rpc.simpleTag("Channel", "Master"); // Master | LF | RF - rpc.invoke(); + XML xml = rpc.invoke(); + try { + xml.open("u:GetVolumeResponse"); + n = Integer.parseInt(xml.read("CurrentVolume").toString()); + if (n < 0) + n = 0; + if (n > 100) + n = 100; + return n; + } catch (XML.Oops x) { + return -1; + } } public void volume(int vol) { // 0-100 if ((vol < 0) || (vol > 100)) @@ -273,6 +285,11 @@ public class Sonos { item.playURI.init(value.unescape()); continue; } + if (name.eq("upnp:class")) { + /* object.item.... vs object.container... */ + if (value.charAt(7) == 'i') + item.flags |= item.SONG; + } } cb.updateItem(_id, n, item); result.close(thing); diff --git a/net/frotz/sonos/SonosItem.java b/net/frotz/sonos/SonosItem.java @@ -7,6 +7,7 @@ public class SonosItem { public XMLSequence artist; public XMLSequence playURI; /* to enqueue */ public XMLSequence idURI; /* for browse/list */ + public int flags; public void reset() { title.adjust(0,0); @@ -14,5 +15,8 @@ public class SonosItem { artist.adjust(0,0); playURI.adjust(0,0); idURI.adjust(0,0); + flags = 0; } + public static final int SONG = 1; + public static final int PLAYLIST = 2; } diff --git a/net/frotz/sonos/app.java b/net/frotz/sonos/app.java @@ -22,8 +22,8 @@ public class app implements SonosListener { Sonos sonos = new Sonos("10.0.0.199"); //sonos.trace_io(true); - //sonos.trace_reply(true); - //sonos.trace_browse(true); + sonos.trace_reply(true); + sonos.trace_browse(true); if (args.length == 0) { sonos.getPosition(); @@ -72,10 +72,12 @@ public class app implements SonosListener { } else if (cmd.equals("track")) { sonos.seekTrack(Integer.parseInt(args[1])); } else if (cmd.equals("volume")) { - if (args.length == 1) - sonos.volume(); - else + if (args.length == 1) { + int n = sonos.volume(); + System.out.println(n); + } else { sonos.volume(Integer.parseInt(args[1])); + } } else { System.err.println("Unknown command '"+cmd+"'"); System.exit(-1);