src/de/uhilger/calypso/App.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/calypso/Server.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/calypso/handler/MPlayHandler.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/calypso/handler/MPlayer.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/calypso/handler/PlayHandler.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/calypso/handler/VLCPlayer.java | ●●●●● patch | view | raw | blame | history |
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; 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)); src/de/uhilger/calypso/handler/MPlayHandler.java
New file @@ -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; } } src/de/uhilger/calypso/handler/MPlayer.java
New file @@ -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(); } } 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(); 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);