App zur Steuerung des mpv Mediaplayers auf einem Raspberry Pi über HTTP
ulrich
2021-04-24 c2c1fd263b9a72779df397f28c5bdd8f4d934524
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();