| | |
| | | |
| | | package de.uhilger.calypso.handler; |
| | | |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import de.uhilger.calypso.App; |
| | | import de.uhilger.calypso.MeldeThread; |
| | | import de.uhilger.calypso.ProzessLauscher; |
| | |
| | | import java.io.OutputStream; |
| | | import java.io.OutputStreamWriter; |
| | | import java.io.Writer; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | |
| | |
| | | * |
| | | * @author ulrich |
| | | */ |
| | | public class OMXPlayer implements Player , ProzessLauscher { |
| | | public class OMXPlayer extends BasePlayer implements Player , ProzessLauscher { |
| | | |
| | | private static final Logger logger = Logger.getLogger(OMXPlayer.class.getName()); |
| | | |
| | |
| | | public static final String CMD_PREV_SUB = "n"; |
| | | public static final String CMD_STOP = "q"; |
| | | public static final String CMD_TOGGLE_SUB = "s"; |
| | | public static final String F_PING = "ping"; |
| | | public static final String F_PLAY = "play"; |
| | | public static final String F_PLAY_ON = "playon"; |
| | | public static final String F_SEEK = "seek"; |
| | | public static final String OPT_HDMI_AUDIO = "-o%20hdmi"; |
| | |
| | | } |
| | | return antwort; |
| | | } |
| | | |
| | | @Override |
| | | public StringBuilder buildParams(HttpExchange t, Map map) { |
| | | StringBuilder params = new StringBuilder(); |
| | | params.append("-o "); |
| | | params.append(getParam(map, "o")); |
| | | params.append(" --threshold "); |
| | | params.append(getParam(map, "th")); |
| | | params.append(" --timeout "); |
| | | params.append(getParam(map, "ti")); |
| | | String log = getParam(map, "log"); |
| | | if (log != null && log.equalsIgnoreCase("true")) { |
| | | params.append(" --genlog"); |
| | | } |
| | | return params; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Einen eventuell laufenden Abspielprozess beenden und den |
| | |
| | | * |
| | | * @return die Antwort des Servers |
| | | */ |
| | | /* |
| | | @Override |
| | | public String tilgen() { |
| | | String antwort; // = null; |
| | |
| | | } |
| | | return antwort; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Dem laufenden Abspielprozess ein Kommando uebermitteln |
| | | * @param k das Kommando laut |
| | | * <a href="https://github.com/huceke/omxplayer/blob/master/README.md" target="_blank">Liste der Kommandos</a> |
| | | * @return die Antwort des Servers |
| | | */ |
| | | @Override |
| | | public String kommando(String k) { |
| | | String antwort; // = null; |
| | | try { |
| | | //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); |
| | | antwort = "Es wird nichts abgespielt dem ein Kommando gesendet werden kann."; |
| | | } else { |
| | | Process player_process = o; |
| | | OutputStream os = player_process.getOutputStream(); |
| | | Writer out = new BufferedWriter(new OutputStreamWriter(os)); |
| | | out.write(k); |
| | | out.flush(); |
| | | if(k.equals(CMD_STOP)) { |
| | | out.close(); |
| | | |
| | | /* |
| | | fuer den Fall, dass ein Stopp-Signal den Player nicht erreicht |
| | | oder dort nicht funktioniert, gibt es keine Moeglichkeit festzustellen, |
| | | dass der Player noch spielt. Damit in einem solchen Fall der Zeiger |
| | | auf den Abspielprozess nicht verloren geht, wird der Zeiger nicht |
| | | auf null gesetzt. |
| | | */ |
| | | |
| | | //App.setPlayerProcess(null); |
| | | //player_process.destroy(); |
| | | //player_process = null; |
| | | //t.setAttribute(App.PI_PLAYER, null); |
| | | //servletContext.removeAttribute(PI_PLAYER); |
| | | } |
| | | antwort = "Kommando '" + k + "' ausgefuehrt."; |
| | | } |
| | | } |
| | | catch(IOException ex) { |
| | | antwort = "Fehler: " + ex.getMessage(); |
| | | } |
| | | return antwort; |
| | | } |
| | | */ |
| | | |
| | | /* ------ Implementierung ProzessLauscher ----------------- */ |
| | | |
| | | /* |
| | | @Override |
| | | public void prozessBeendet(String meldeUrlStr) { |
| | | try { |
| | |
| | | auf null gesetzt. |
| | | */ |
| | | //App.setPlayerProcess(null); |
| | | /* |
| | | } catch(IOException ex) { |
| | | logger.log(Level.INFO, ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | | */ |
| | | } |