use of net.pms.util.BasicPlayer.Logical in project UniversalMediaServer by UniversalMediaServer.
the class PlayerControlHandler method getRenderers.
public String getRenderers(InetAddress client) {
Logical player = selectedPlayers.get(client);
RendererConfiguration selected = player != null ? player.renderer : getDefaultRenderer();
ArrayList<String> json = new ArrayList<>();
for (RendererConfiguration r : RendererConfiguration.getConnectedControlPlayers()) {
json.add(String.format("[\"%s\",%d,\"%s\"]", (r instanceof WebRender) ? r.uuid : r, r == selected ? 1 : 0, r.uuid));
}
return "\"renderers\":[" + StringUtils.join(json, ",") + "]";
}
use of net.pms.util.BasicPlayer.Logical in project UniversalMediaServer by UniversalMediaServer.
the class PlayerControlHandler method getPlayer.
public Logical getPlayer(String uuid) {
Logical player = players.get(uuid);
if (player == null) {
try {
RendererConfiguration renderer = RendererConfiguration.getRendererConfigurationByUUID(uuid);
if (renderer != null) {
player = (Logical) renderer.getPlayer();
players.put(uuid, player);
}
} catch (Exception e) {
LOGGER.debug("Error retrieving player {}: {}", uuid, e.getMessage());
LOGGER.trace("", e);
}
}
return player;
}
use of net.pms.util.BasicPlayer.Logical in project UniversalMediaServer by UniversalMediaServer.
the class PlayerControlHandler method handle.
@Override
public void handle(HttpExchange httpExchange) throws IOException {
if (RemoteUtil.deny(httpExchange) && !RemoteUtil.bumpAllowed(httpExchange)) {
LOGGER.debug("Denying {}", httpExchange);
throw new IOException("Denied");
}
String[] p = httpExchange.getRequestURI().getPath().split("/");
Map<String, String> query = parseQuery(httpExchange);
String response = "";
String mime = "text/html";
boolean log = true;
ArrayList<String> json = new ArrayList<>();
String uuid = p.length > 3 ? p[3] : null;
Logical player = uuid != null ? getPlayer(uuid) : null;
if (player != null) {
switch(p[2]) {
case "status":
// limit status updates to one per second
UPNPHelper.sleep(1000);
log = false;
break;
case "play":
player.pressPlay(translate(query.get("uri")), query.get("title"));
break;
case "stop":
player.pressStop();
break;
case "prev":
player.prev();
break;
case "next":
player.next();
break;
case "fwd":
player.forward();
break;
case "rew":
player.rewind();
break;
case "mute":
player.mute();
break;
case "setvolume":
player.setVolume(Integer.parseInt(query.get("vol")));
break;
case "add":
player.add(-1, translate(query.get("uri")), query.get("title"), null, true);
break;
case "remove":
player.remove(translate(query.get("uri")));
break;
case "clear":
player.clear();
break;
case "seturi":
player.setURI(translate(query.get("uri")), query.get("title"));
break;
}
json.add(getPlayerState(player));
json.add(getPlaylist(player));
selectedPlayers.put(httpExchange.getRemoteAddress().getAddress(), player);
} else if (p.length == 2) {
response = parent.getResources().read("bump/bump.html").replace("http://127.0.0.1:9001", protocol + PMS.get().getServer().getHost() + ":" + port);
} else if (p[2].equals("bump.js")) {
response = getBumpJS();
mime = "text/javascript";
} else if (p[2].equals("renderers")) {
json.add(getRenderers(httpExchange.getRemoteAddress().getAddress()));
} else if (p[2].startsWith("skin.")) {
RemoteUtil.dumpFile(new File(skindir, p[2].substring(5)), httpExchange);
return;
}
if (json.size() > 0) {
if (player != null) {
json.add("\"uuid\":\"" + uuid + "\"");
}
response = "{" + StringUtils.join(json, ",") + "}";
}
if (log) {
LOGGER.debug("Received http player control request from {}: {}", httpExchange.getRemoteAddress().getAddress(), httpExchange.getRequestURI());
}
Headers headers = httpExchange.getResponseHeaders();
headers.add("Content-Type", mime);
// w/o this client may receive response status 0 and no content
headers.add("Access-Control-Allow-Origin", "*");
byte[] bytes = response.getBytes(StandardCharsets.UTF_8);
httpExchange.sendResponseHeaders(200, bytes.length);
try (OutputStream o = httpExchange.getResponseBody()) {
o.write(bytes);
}
}
Aggregations