| | |
| | | public static final String SP_RUECK_600 = "rueck600"; |
| | | |
| | | public static final String OPT_LOCAL_AUDIO = "-o%20local"; |
| | | public static final String OPT_HDMI_AUDIO = "-o hdmi"; |
| | | public static final String OPT_HDMI_AUDIO = "-o%20hdmi"; |
| | | |
| | | public static final String F_PLAY = "play"; |
| | | public static final String F_SEEK = "seek"; |
| | | public static final String F_PING = "ping"; |
| | | |
| | | public static final String BLANK = " "; |
| | | |
| | |
| | | logger.info("Server starting on port " + port); |
| | | |
| | | HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); |
| | | server.createContext("/avd/play", new PlayHandler("play")); |
| | | server.createContext("/avd/seek", new SeekHandler("seek")); |
| | | server.createContext("/avd/play", new PlayHandler(App.F_PLAY)); |
| | | server.createContext("/avd/seek", new SeekHandler(App.F_SEEK)); |
| | | server.createContext("/avd/stop", new CmdHandler(App.CMD_STOP)); |
| | | server.createContext("/avd/pause", new CmdHandler(App.CMD_PAUSE_RESUME)); |
| | | server.createContext("/avd/ping", new PingHandler()); |
| | | server.createContext("/avd/ping", new PingHandler(App.F_PING)); |
| | | server.createContext("/avd/server/stop", new StopServerHandler()); |
| | | //server.setExecutor(null); // creates a default executor |
| | | server.setExecutor(Executors.newFixedThreadPool(20)); |
| | |
| | | package de.uhilger.avdirektor.handler; |
| | | |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import com.sun.net.httpserver.HttpHandler; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | |
| | |
| | | * |
| | | * @author ulrich |
| | | */ |
| | | public class PingHandler implements HttpHandler { |
| | | public class PingHandler extends CmdHandler { |
| | | |
| | | private static final Logger logger = Logger.getLogger(PingHandler.class.getName()); |
| | | |
| | | public PingHandler(String cmd) { |
| | | super(cmd); |
| | | } |
| | | |
| | | /* |
| | | @Override |
| | | public void handle(HttpExchange t) throws IOException { |
| | | logger.log(Level.FINE, "RequestURI: {0}", t.getRequestURI().toString()); |
| | |
| | | os.write(response.getBytes()); |
| | | os.close(); |
| | | } |
| | | */ |
| | | |
| | | protected String process(HttpExchange t, String params) { |
| | | String antwort = cmd; |
| | | logger.log(Level.FINE, antwort); |
| | | return antwort; |
| | | } |
| | | |
| | | } |
| | |
| | | import java.util.logging.Logger; |
| | | |
| | | /** |
| | | * Play |
| | | * |
| | | * rpi4-az:9090/avd/play?titel=/Filme/S/sound_city.m4v&th=60&ti=60&o=local |
| | | * |
| | | * OMXPlayer.abspielenMitParameternUndRueckmeldung( |
| | | * String urlStr, String parameter, String meldeUrlStr, String token) |
| | | * |
| | | * Parameter des Aufrufs play als query (th threshold, ti timeout) |
| | | * |
| | | * ?titel=/Filme/S/sound_city.m4v |
| | | * &ti=60 |
| | | * &th=60 |
| | | * &o=local|hdmi|both |
| | | * &r=http://uhilger.de/mc/api/usw |
| | | * |
| | | * r muss ganz wegbleiben, wenn keine Rueckmeldung gewuescht ist |
| | | * |
| | | * @author ulrich |
| | | */ |
| | |
| | | public PlayHandler(String cmd) { |
| | | super(cmd); |
| | | } |
| | | |
| | | /* |
| | | rpi4-az:9090/avd/play?titel=/Filme/S/sound_city.m4v&th=60&ti=60&o=local |
| | | |
| | | OMXPlayer.abspielenMitParameternUndRueckmeldung( |
| | | String urlStr, String parameter, String meldeUrlStr, String token) |
| | | |
| | | Parameter des Aufrufs play als query (th threshold, ti timeout) |
| | | |
| | | ?titel=/Filme/S/sound_city.m4v |
| | | &ti=60 |
| | | &th=60 |
| | | &o=local|hdmi|both |
| | | &r=http://uhilger.de/mc/api/usw |
| | | |
| | | r muss ganz wegbleiben, wenn keine Rueckmeldung gewuescht ist |
| | | |
| | | */ |
| | | /* |
| | | @Override |
| | | public void handle(HttpExchange t) throws IOException { |
| | | logger.log(Level.FINE, "RequestURI: {0}", t.getRequestURI().toString()); |
| | | |
| | | StringBuilder params = buildParams(t); |
| | | |
| | | String antwort = abspielenMitParameternUndRueckmeldung( |
| | | getParam(map, "titel"), params.toString(), getParam(map, "r"), "1"); |
| | | |
| | | sendResponse(t, "play", antwort); |
| | | } |
| | | */ |
| | | |
| | | @Override |
| | | protected String process(HttpExchange t, String params) { |
| | |
| | | package de.uhilger.avdirektor.handler; |
| | | |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import com.sun.net.httpserver.HttpHandler; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.util.Map; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | |
| | |
| | | super(cmd); |
| | | } |
| | | |
| | | /* |
| | | @Override |
| | | public void handle(HttpExchange t) throws IOException { |
| | | logger.log(Level.FINE, "RequestURI: {0}", t.getRequestURI().toString()); |
| | | |
| | | StringBuilder params = super.buildParams(t); |
| | | params.append(" --pos "); |
| | | params.append(getParam(map, "p")); |
| | | |
| | | String antwort = abspielenMitParameternUndRueckmeldung( |
| | | getParam(map, "titel"), params.toString(), getParam(map, "r"), "1"); |
| | | |
| | | String response = getResponseString(map, "play", antwort); |
| | | t.sendResponseHeaders(200, response.length()); |
| | | OutputStream os = t.getResponseBody(); |
| | | os.write(response.getBytes()); |
| | | os.close(); |
| | | } |
| | | */ |
| | | |
| | | @Override |
| | | protected String process(HttpExchange t, String params) { |
| | | String antwort = abspielenMitParameternUndRueckmeldung( |
| | |
| | | * |
| | | * @author ulrich |
| | | */ |
| | | public class StopServerHandler implements HttpHandler { |
| | | public class StopServerHandler extends OMXPlayer implements HttpHandler { |
| | | |
| | | @Override |
| | | public void handle(HttpExchange exchange) throws IOException { |
| | | Logger.getLogger(StopServerHandler.class.getName()).info(exchange.getRequestURI().toString()); |
| | | this.kommando(App.CMD_STOP); |
| | | String response = "Server stopped"; |
| | | exchange.sendResponseHeaders(200, response.length()); |
| | | OutputStream os = exchange.getResponseBody(); |