App zur Steuerung des mpv Mediaplayers auf einem Raspberry Pi über HTTP
ulrich
2021-03-31 15ed25a13d5f8340dfecef50d23173aef45af125
OMXPlayer Log (in Arbeit)
2 files modified
2 files added
87 ■■■■■ changed files
src/de/uhilger/avdirektor/OMXLogLeser.java 51 ●●●●● patch | view | raw | blame | history
src/de/uhilger/avdirektor/Server.java 2 ●●●●● patch | view | raw | blame | history
src/de/uhilger/avdirektor/handler/LogHandler.java 30 ●●●●● patch | view | raw | blame | history
src/de/uhilger/avdirektor/handler/PlayHandler.java 4 ●●●● patch | view | raw | blame | history
src/de/uhilger/avdirektor/OMXLogLeser.java
New file
@@ -0,0 +1,51 @@
package de.uhilger.avdirektor;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.Logger;
/**
 *
 * @author ulrich
 */
public class OMXLogLeser {
  private static final Logger logger = Logger.getLogger(OMXLogLeser.class.getName());
  public String lesen(File logfile) throws FileNotFoundException, IOException {
    InputStream is = new FileInputStream(logfile);
    BufferedReader r = new BufferedReader(new InputStreamReader(is));
    String firstLine = r.readLine();
    String lastLine = "";
    if(firstLine != null) {
      long size = logfile.length();
      long pos = size - (long) 1000;
      logger.info("Size: " + size + ", Pos: " + pos); // 2.341.930 Bytes
      long skipped = r.skip(pos);
      logger.info("skipped: " + skipped);
      String line = r.readLine();
      while(line != null) {
        lastLine = line;
        logger.info(lastLine);
        line = r.readLine();
      }
    }
    r.close();
    is.close();
    StringBuilder sb = new StringBuilder();
    sb.append("\r\n---");
    sb.append("\r\nfirst line:\r\n");
    sb.append(firstLine);
    sb.append("\r\n\r\nlastLine\r\n");
    sb.append(lastLine);
    String lines = sb.toString();
    logger.info(lines);
    return lines;
  }
}
src/de/uhilger/avdirektor/Server.java
@@ -21,6 +21,7 @@
import com.sun.net.httpserver.HttpServer;
import de.uhilger.avdirektor.handler.CmdHandler;
import de.uhilger.avdirektor.handler.FileHandler;
import de.uhilger.avdirektor.handler.LogHandler;
import de.uhilger.avdirektor.handler.OMXPlayer;
import de.uhilger.avdirektor.handler.PingHandler;
import de.uhilger.avdirektor.handler.PlayHandler;
@@ -61,6 +62,7 @@
    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/ui", new FileHandler(App.getInitParameter(App.IP_WWW_DATA)));
    //server.setExecutor(null); // creates a default executor
    server.setExecutor(Executors.newFixedThreadPool(20));
src/de/uhilger/avdirektor/handler/LogHandler.java
New file
@@ -0,0 +1,30 @@
package de.uhilger.avdirektor.handler;
import com.sun.net.httpserver.HttpExchange;
import de.uhilger.avdirektor.OMXLogLeser;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author ulrich
 */
public class LogHandler extends AbstractHandler {
  private static final Logger logger = Logger.getLogger(LogHandler.class.getName());
  @Override
  protected String process(HttpExchange t, String params) {
    OMXLogLeser leser = new OMXLogLeser();
    String lines = "Log nicht lesbar.";
    try {
      lines = leser.lesen(new File("/home/ulrich/work/avd/omxplayer.log"));
    } catch (IOException ex) {
      Logger.getLogger(LogHandler.class.getName()).log(Level.SEVERE, null, ex);
    }
    return lines;
  }
}
src/de/uhilger/avdirektor/handler/PlayHandler.java
@@ -67,6 +67,10 @@
    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;
  }