App zur Steuerung des mpv Mediaplayers auf einem Raspberry Pi über HTTP
ulrich
2021-04-24 c2c1fd263b9a72779df397f28c5bdd8f4d934524
Umbenannt zu Calypso
4 files modified
45 ■■■■■ changed files
resources/logging.properties 4 ●●●● patch | view | raw | blame | history
resources/start 2 ●●● patch | view | raw | blame | history
src/de/uhilger/calypso/App.java 11 ●●●● patch | view | raw | blame | history
src/de/uhilger/calypso/Server.java 28 ●●●●● patch | view | raw | blame | history
resources/logging.properties
@@ -68,5 +68,5 @@
# de.uhilger.filecms.level = FINEST
# de.uhilger.wbx.handlers = java.util.logging.ConsoleHandler
# de.uhilger.wbx.level = FINEST
de.uhilger.avdirektor.handlers = java.util.logging.FileHandler, java.util.logging.ConsoleHandler
de.uhilger.avdirektor.level = FINEST
de.uhilger.calypso.handlers = java.util.logging.FileHandler, java.util.logging.ConsoleHandler
de.uhilger.calypso.level = FINEST
resources/start
@@ -1,3 +1,3 @@
#!/bin/sh
java -Domx.wd=/mnt/store/avd -Djava.util.logging.config.file=logging.properties -jar av-direktor.jar port=9090 player=omx &
java -Domx.wd=/mnt/store/avd -Djava.util.logging.config.file=logging.properties -jar calypso.jar port=9090 player=omx ctx=/calypso &
src/de/uhilger/calypso/App.java
@@ -30,7 +30,7 @@
 * Hauptklasse des av-director
 * 
 * Aufruf mit
 * java -jar av-director.jar port=9000
 * java -jar av-director.jar port=9000 ctx="/calypso"
 * java -jar av-director.jar nfs-prefix="/media/mc" port=9000
 * java -Djava.util.logging.config.file=logging.properties -jar ..
 * 
@@ -52,12 +52,13 @@
  public static final String VLC_PLAYER = "vlc";
  public static final String OMX_PLAYER = "omx";
  public static final String OMX_WD = "omx.wd";
  public static final String CTX = "ctx";
  
  public static final String DEFAULT_CTX = "/calypso";
  
  private static HashMap initParams;  
  private static Process playerproc;
  private static Player player;
  
  /**
   * @param args the command line arguments
@@ -79,6 +80,12 @@
        break;
    }
    Server server = new Server(Integer.parseInt(getInitParameter(IP_PORT)));
    String ctx = getInitParameter(CTX);
    if(ctx != null && ctx.length() > 0) {
      server.setContextName(ctx);
    } else {
      server.setContextName(DEFAULT_CTX);
    }
    try {
      server.start();
    } catch (IOException ex) {
src/de/uhilger/calypso/Server.java
@@ -43,6 +43,8 @@
  private int port;
  
  private String contextName;
  public Server(int port) {
    this.port = port;
  }
@@ -51,19 +53,27 @@
    this.port = port;
  }
  
  /**
   *
   * @param contextName e.g. '/calypso' or '/cal'
   */
  public void setContextName(String contextName) {
    this.contextName = contextName;
  }
  public void start() throws IOException {
    logger.info("Server starting on port " + port);
    HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
    server.createContext("/avd/play", new PlayHandler(OMXPlayer.F_PLAY));
    server.createContext("/avd/seek", new SeekHandler(OMXPlayer.F_SEEK));
    server.createContext("/avd/stop", new CmdHandler(OMXPlayer.CMD_STOP));
    server.createContext("/avd/pause", new CmdHandler(OMXPlayer.CMD_PAUSE_RESUME));
    server.createContext("/avd/ping", new PingHandler(OMXPlayer.F_PING));
    server.createContext("/avd/server/stop", new StopServerHandler());
    server.createContext("/avd/log", new LogHandler());
    server.createContext("/avd/playon", new PlayOnHandler(OMXPlayer.F_PLAY_ON));
    server.createContext("/avd/ui", new FileHandler(App.getInitParameter(App.IP_WWW_DATA)));
    server.createContext(contextName + "/play", new PlayHandler(OMXPlayer.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));
    server.createContext(contextName + "/ping", new PingHandler(OMXPlayer.F_PING));
    server.createContext(contextName + "/server/stop", new StopServerHandler());
    server.createContext(contextName + "/log", new LogHandler());
    server.createContext(contextName + "/playon", new PlayOnHandler(OMXPlayer.F_PLAY_ON));
    server.createContext(contextName + "/ui", new FileHandler(App.getInitParameter(App.IP_WWW_DATA)));
    //server.setExecutor(null); // creates a default executor
    server.setExecutor(Executors.newFixedThreadPool(20));
    server.start();