From a7f0a18275d394ff92e44fcce55a511a54535787 Mon Sep 17 00:00:00 2001 From: ulrich Date: Mon, 22 Mar 2021 11:57:53 +0000 Subject: [PATCH] Play/Stop erste fertige Fassung --- src/de/uhilger/avdirektor/handler/OMXPlayer.java | 82 +++++++++++++++++++++++++++++++---------- 1 files changed, 62 insertions(+), 20 deletions(-) diff --git a/src/de/uhilger/avdirektor/handler/OMXPlayer.java b/src/de/uhilger/avdirektor/handler/OMXPlayer.java index dc0a797..252c8ce 100644 --- a/src/de/uhilger/avdirektor/handler/OMXPlayer.java +++ b/src/de/uhilger/avdirektor/handler/OMXPlayer.java @@ -39,15 +39,50 @@ } } + /* + + bei etwas wie + http://rpi4-az:9090/avd/play?t=/Filme/S/sound_city.m4v&p=--timeout=60%20--threshold=60 + + sind = nicht nur nach dem Query-Parameter sondern auch in dessen Wert + + also erstmal nach & zerlegen: + t=/Filme/S/sound_city.m4v + p=--timeout=60%20--threshold=60 + + dann die Position beim ersten = von links abschneiden + + */ protected Map getQueryMap(HttpExchange t) { HashMap map = new HashMap(); String query = t.getRequestURI().getQuery(); if(query != null && query.length() > 0) { String qParts[] = query.split("&"); for(String qPart : qParts) { - //logger.info("qPart: " + qPart); + logger.finer("qPart: " + qPart); String pParts[] = qPart.split("="); map.put(pParts[0], pParts[1]); + logger.finer("pParts[0]: " + pParts[0] + ", pParts[1]: " + pParts[1]); + /* + if(qPart.contains(" ")) { + String pParts[] = qPart.split(" "); + for(String pPart : pParts) { + String ppParts[] = pPart.split("="); + map.put(ppParts[0], ppParts[1]); + logger.finer("ppParts[0]: " + ppParts[0] + ", ppParts[1]: " + ppParts[1]); + } + } else { + String pParts[] = qPart.split("="); + map.put(pParts[0], pParts[1]); + logger.finer("pParts[0]: " + pParts[0] + ", pParts[1]: " + pParts[1]); + } + */ + /* + String pParts[] = qPart.split("="); + for(String pPart : pParts) { + logger.finer("pPart: " + pPart); + } + */ } } return map; @@ -78,12 +113,12 @@ * @param token * @return Antwort des Servers */ - public String abspielen(HttpExchange t, String urlStr, String token) { - return abspielenMitParametern(t, urlStr, null, token); + public String abspielen(String urlStr, String token) { + return abspielenMitParametern(urlStr, null, token); } - public String abspielenMitRueckmeldung(HttpExchange t, String urlStr, String meldeUrlStr, String token) { - return abspielenMitParameternUndRueckmeldung(t, urlStr, null, meldeUrlStr, token); + public String abspielenMitRueckmeldung(String urlStr, String meldeUrlStr, String token) { + return abspielenMitParameternUndRueckmeldung(urlStr, null, meldeUrlStr, token); } /** @@ -99,16 +134,17 @@ * @param token * @return Antwort des Servers */ - public String abspielenMitParametern(HttpExchange t, String urlStr, String parameter, String token) { - return abspielenMitParameternUndRueckmeldung(t, urlStr, parameter, null, token); + public String abspielenMitParametern(String urlStr, String parameter, String token) { + return abspielenMitParameternUndRueckmeldung(urlStr, parameter, null, token); } - public String abspielenMitParameternUndRueckmeldung(HttpExchange t, String urlStr, String parameter, String meldeUrlStr, String token) { + public String abspielenMitParameternUndRueckmeldung(String urlStr, String parameter, String meldeUrlStr, String token) { String antwort;// = null; try { - Object o = t.getAttribute(App.PI_PLAYER); + //Object o = t.getAttribute(App.PI_PLAYER); + Process o = App.getPlayerProcess(); if(o != null) { - tilgen(t); + tilgen(); } StringBuilder kommando = new StringBuilder("omxplayer "); if(parameter != null) { @@ -147,7 +183,8 @@ mt.start(); } //servletContext.setAttribute(App.PI_PLAYER, player_process); - t.setAttribute(App.PI_PLAYER, player_process); + //t.setAttribute(App.PI_PLAYER, player_process); + App.setPlayerProcess(player_process); //Runtime.getRuntime().exec("killall dbus-daemon"); antwort = "Abspielen gestartet, url: " + urlStr; } @@ -171,16 +208,18 @@ * @param t * @return die Antwort des Servers */ - public String tilgen(HttpExchange t) { + public String tilgen() { String antwort; // = null; try { - Object o = t.getAttribute(App.PI_PLAYER); + //Object o = t.getAttribute(App.PI_PLAYER); + Process o = App.getPlayerProcess(); if(o == null) { - t.setAttribute(App.PI_PLAYER, null); + //t.setAttribute(App.PI_PLAYER, null); + App.setPlayerProcess(null); // t.removeAttribute(App.PI_PLAYER); antwort = "Es ist kein Player zum Beenden vorhanden, aber der Servlet-Kontext wurde bereinigt."; } else { - kommando(t, App.CMD_STOP); + kommando(App.CMD_STOP); //t.removeAttribute(PI_PLAYER); antwort = "Player gestoppt, Kontext bereinigt."; } @@ -199,25 +238,28 @@ * <a href="https://github.com/huceke/omxplayer/blob/master/README.md" target="_blank">Liste der Kommandos</a> * @return die Antwort des Servers */ - public String kommando(HttpExchange t, String k) { + public String kommando(String k) { String antwort; // = null; try { - Object o = t.getAttribute(App.PI_PLAYER); + //Object o = t.getAttribute(App.PI_PLAYER); + Process o = App.getPlayerProcess(); if(o == null) { + App.setPlayerProcess(null); //servletContext.removeAttribute(PI_PLAYER); - t.setAttribute(App.PI_PLAYER, null); + //t.setAttribute(App.PI_PLAYER, null); antwort = "Es wird nichts abgespielt dem ein Kommando gesendet werden kann."; } else { - Process player_process = (Process) o; + Process player_process = o; OutputStream os = player_process.getOutputStream(); Writer out = new BufferedWriter(new OutputStreamWriter(os)); out.write(k); out.flush(); if(k.equals(App.CMD_STOP)) { out.close(); + App.setPlayerProcess(null); //player_process.destroy(); //player_process = null; - t.setAttribute(App.PI_PLAYER, null); + //t.setAttribute(App.PI_PLAYER, null); //servletContext.removeAttribute(PI_PLAYER); } antwort = "Kommando '" + k + "' ausgefuehrt."; -- Gitblit v1.9.3