From 7a79ba8b70e8541b6d4413a46061b2c03ecddc9b Mon Sep 17 00:00:00 2001 From: undisclosed Date: Tue, 03 Jan 2023 10:47:17 +0000 Subject: [PATCH] Baustelle: Versuche mit unterschiedlichen Playern --- src/de/uhilger/calypso/App.java | 5 + src/de/uhilger/calypso/Server.java | 11 +++ src/de/uhilger/calypso/handler/MPlayHandler.java | 27 +++++++++ src/de/uhilger/calypso/handler/MPlayer.java | 88 +++++++++++++++++++++++++++++ src/de/uhilger/calypso/handler/VLCPlayer.java | 2 src/de/uhilger/calypso/handler/PlayHandler.java | 2 6 files changed, 132 insertions(+), 3 deletions(-) diff --git a/src/de/uhilger/calypso/App.java b/src/de/uhilger/calypso/App.java index 92111cb..48307cb 100644 --- a/src/de/uhilger/calypso/App.java +++ b/src/de/uhilger/calypso/App.java @@ -18,6 +18,7 @@ package de.uhilger.calypso; +import de.uhilger.calypso.handler.MPlayer; import de.uhilger.calypso.handler.OMXPlayer; import de.uhilger.calypso.handler.Player; import de.uhilger.calypso.handler.VLCPlayer; @@ -57,6 +58,7 @@ public static final String IP_PLAYER = "player"; public static final String VLC_PLAYER = "vlc"; public static final String OMX_PLAYER = "omx"; + public static final String M_PLAYER = "mpl"; public static final String OMX_WD = "omx.wd"; public static final String CTX = "ctx"; @@ -78,6 +80,9 @@ String playerType = getInitParameter(IP_PLAYER); switch(playerType) { + case M_PLAYER: + player = new MPlayer(); + break; case VLC_PLAYER: player = new VLCPlayer(); break; diff --git a/src/de/uhilger/calypso/Server.java b/src/de/uhilger/calypso/Server.java index df18287..1c01d35 100644 --- a/src/de/uhilger/calypso/Server.java +++ b/src/de/uhilger/calypso/Server.java @@ -23,6 +23,8 @@ import de.uhilger.calypso.handler.DBusHandler; import de.uhilger.calypso.handler.FileHandler; import de.uhilger.calypso.handler.LogHandler; +import de.uhilger.calypso.handler.MPlayHandler; +import de.uhilger.calypso.handler.MPlayer; import de.uhilger.calypso.handler.OMXPlayer; import de.uhilger.calypso.handler.PingHandler; import de.uhilger.calypso.handler.PlayHandler; @@ -93,8 +95,9 @@ logger.log(Level.INFO, "Server starting on port {0}", port); HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); - server.createContext(contextName + "/play", new PlayHandler(BasePlayer.F_PLAY)); + if (playerType.equals(App.OMX_PLAYER)) { + server.createContext(contextName + "/play", new PlayHandler(BasePlayer.F_PLAY)); server.createContext(contextName + "/seek", new SeekHandler(OMXPlayer.F_SEEK)); server.createContext(contextName + "/stop", new CmdHandler(OMXPlayer.CMD_STOP)); server.createContext(contextName + "/pause", new CmdHandler(OMXPlayer.CMD_PAUSE_RESUME)); @@ -104,10 +107,16 @@ server.createContext(contextName + "/log", new LogHandler()); server.createContext(contextName + "/playon", new PlayOnHandler(OMXPlayer.F_PLAY_ON)); } else if (playerType.equals(App.VLC_PLAYER)) { + server.createContext(contextName + "/play", new PlayHandler(BasePlayer.F_PLAY)); server.createContext(contextName + "/pause", new DBusHandler(VLCPlayer.CMD_PAUSE_RESUME)); + //server.createContext(contextName + "/pause", new CmdHandler("pause")); //server.createContext(contextName + "/seek", new DBusHandler(VLCPlayer.CMD_SEEK)); server.createContext(contextName + "/seek", new VLCSeekHandler(VLCPlayer.CMD_SEEK)); server.createContext(contextName + "/stop", new VLCKillHandler()); + } else if (playerType.equals(App.M_PLAYER)) { + server.createContext(contextName + "/play", new MPlayHandler()); + server.createContext(contextName + "/pause", new CmdHandler(MPlayer.CMD_PAUSE_RESUME)); + server.createContext(contextName + "/stop", new CmdHandler(MPlayer.CMD_STOP)); } server.createContext(contextName + "/ui", new FileHandler(App.getInitParameter(App.IP_WWW_DATA))); server.createContext(contextName + "/ping", new PingHandler(BasePlayer.F_PING)); diff --git a/src/de/uhilger/calypso/handler/MPlayHandler.java b/src/de/uhilger/calypso/handler/MPlayHandler.java new file mode 100644 index 0000000..7ccb685 --- /dev/null +++ b/src/de/uhilger/calypso/handler/MPlayHandler.java @@ -0,0 +1,27 @@ +package de.uhilger.calypso.handler; + +import com.sun.net.httpserver.HttpExchange; +import de.uhilger.calypso.App; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Ulrich Hilger + */ +public class MPlayHandler extends AbstractHandler { + + private static final Logger logger = Logger.getLogger(MPlayHandler.class.getName()); + + @Override + protected String process(HttpExchange t, String params) { + Player player = App.getPlayer(); + String antwort = player.abspielen( + player.getParam(map, "titel"), params, player.getParam(map, "r"), "1"); + logger.log(Level.FINE, antwort); + return antwort; + } + + + +} diff --git a/src/de/uhilger/calypso/handler/MPlayer.java b/src/de/uhilger/calypso/handler/MPlayer.java new file mode 100644 index 0000000..6539233 --- /dev/null +++ b/src/de/uhilger/calypso/handler/MPlayer.java @@ -0,0 +1,88 @@ +package de.uhilger.calypso.handler; + +import com.sun.net.httpserver.HttpExchange; +import de.uhilger.calypso.App; +import de.uhilger.calypso.MeldeThread; +import java.io.IOException; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Ulrich Hilger + */ +public class MPlayer extends BasePlayer { + + private static final Logger logger = Logger.getLogger(MPlayer.class.getName()); + + public static final String CMD_STOP = "q"; + public static final String CMD_PAUSE_RESUME = "p"; + + @Override + public String abspielen(String urlStr, String parameter, String meldeUrlStr, String token) { + String antwort;// = null; + try { + //Object o = t.getAttribute(App.PI_PLAYER); + Process o = App.getPlayerProcess(); + if(o != null) { + tilgen(); + } + StringBuilder kommando = new StringBuilder("mplayer -cache 2048 -cache-min 80 -really-quiet -framedrop "); + /* + if(parameter != null) { + kommando.append(parameter); + kommando.append(BLANK); + } + */ + if(urlStr.startsWith("http")) { + kommando.append(urlStr.replace(" ", "%20")); + //kommando.append("?t="); + //kommando.append(token); + } else { + /* + //url z.B.: Filme/H/HEAT_D2.m4v + + hier muss noch der Pfad hinzugefuegt werden, unter + dem auf dem raspi die Datenquelle via NFS eingebunden ist, + z.B. /media/mc/ + dieser Teil des Pfades muss in pirc als Init-Parameter oder + etwas aehnliches hinterlegt sein, weil es lokal zum jeweils + verwendeten raspi gehoert + + */ + + String pfad = App.getInitParameter("nfs-prefix"); + kommando.append(pfad); + + kommando.append(urlStr); + } + //kommando.append(" vlc://quit"); + //kommando.append(" >>/dev/null 2>&1"); + logger.log(Level.FINE, "kommando: {0}", kommando.toString()); + Process player_process = Runtime.getRuntime().exec(kommando.toString()); + if(meldeUrlStr != null) { + MeldeThread mt = new MeldeThread(); + mt.setProcess(player_process); + mt.lauscherHinzufuegen(this); + mt.setMeldeUrl(meldeUrlStr); + mt.start(); + } + //servletContext.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; + } + catch(IOException ex) { + antwort = "Fehler: " + ex.getMessage(); + } + return antwort; + } + + @Override + public StringBuilder buildParams(HttpExchange t, Map m) { + return new StringBuilder(); + } + +} diff --git a/src/de/uhilger/calypso/handler/PlayHandler.java b/src/de/uhilger/calypso/handler/PlayHandler.java index 86b99b4..7b09208 100644 --- a/src/de/uhilger/calypso/handler/PlayHandler.java +++ b/src/de/uhilger/calypso/handler/PlayHandler.java @@ -83,7 +83,7 @@ @Override protected String process(HttpExchange t, String params) { - if (cmd.equalsIgnoreCase(OMXPlayer.F_PLAY)) { + if (cmd.equalsIgnoreCase(BasePlayer.F_PLAY)) { try { //FileUtils.deleteDirectory(new File(System.getProperty("omx.wd"), "omx-logs")); FileSystem fs = FileSystems.getDefault(); diff --git a/src/de/uhilger/calypso/handler/VLCPlayer.java b/src/de/uhilger/calypso/handler/VLCPlayer.java index c2c1aba..1fac570 100644 --- a/src/de/uhilger/calypso/handler/VLCPlayer.java +++ b/src/de/uhilger/calypso/handler/VLCPlayer.java @@ -31,7 +31,7 @@ if(o != null) { tilgen(); } - StringBuilder kommando = new StringBuilder("vlc --fullscreen "); + StringBuilder kommando = new StringBuilder("vlc --fullscreen -I rc "); /* if(parameter != null) { kommando.append(parameter); -- Gitblit v1.9.3