From ac496f2285d0f79b0124528edd636a732739829a Mon Sep 17 00:00:00 2001
From: undisclosed
Date: Sun, 01 Jan 2023 17:29:03 +0000
Subject: [PATCH] Seek fuer VLC eingebaut

---
 src/de/uhilger/calypso/handler/DBusHandler.java    |   25 +++++++++---
 src/de/uhilger/calypso/Server.java                 |    3 +
 src/de/uhilger/calypso/handler/VLCPlayer.java      |    4 +
 src/de/uhilger/calypso/handler/VLCSeekHandler.java |   61 ++++++++++++++++++++++++++++++
 4 files changed, 85 insertions(+), 8 deletions(-)

diff --git a/src/de/uhilger/calypso/Server.java b/src/de/uhilger/calypso/Server.java
index 0cd0c61..cab92a6 100644
--- a/src/de/uhilger/calypso/Server.java
+++ b/src/de/uhilger/calypso/Server.java
@@ -31,6 +31,7 @@
 import de.uhilger.calypso.handler.StopServerHandler;
 import de.uhilger.calypso.handler.VLCKillHandler;
 import de.uhilger.calypso.handler.VLCPlayer;
+import de.uhilger.calypso.handler.VLCSeekHandler;
 import java.io.IOException;
 import java.util.logging.Logger;
 import java.net.InetSocketAddress;
@@ -81,6 +82,8 @@
       server.createContext(contextName + "/playon", new PlayOnHandler(OMXPlayer.F_PLAY_ON));
     } else if (playerType.equals(App.VLC_PLAYER)) {
       server.createContext(contextName + "/pause", new DBusHandler(VLCPlayer.CMD_PAUSE_RESUME));
+      //server.createContext(contextName + "/seek", new DBusHandler(VLCPlayer.CMD_SEEK));
+      server.createContext(contextName + "/seek", new VLCSeekHandler(VLCPlayer.CMD_SEEK));
       server.createContext(contextName + "/stop", new VLCKillHandler());
     }
     server.createContext(contextName + "/ui", new FileHandler(App.getInitParameter(App.IP_WWW_DATA)));
diff --git a/src/de/uhilger/calypso/handler/DBusHandler.java b/src/de/uhilger/calypso/handler/DBusHandler.java
index 07b0bb4..0f6be4d 100644
--- a/src/de/uhilger/calypso/handler/DBusHandler.java
+++ b/src/de/uhilger/calypso/handler/DBusHandler.java
@@ -1,21 +1,30 @@
 package de.uhilger.calypso.handler;
 
 import com.sun.net.httpserver.HttpExchange;
+import de.uhilger.calypso.App;
 import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * Obwohl ein laufendes VLC-Programm mit Tastaturbefehlen gesteuert 
  * werden kann, funktioniert es nicht, dem Prozess einen Tastaturbefehl
- * wie z.B. S fuer Stopp ueber process.getOutputStream zu 'schreiben'.
+ * wie z.B. S fuer Stopp ueber process.getOutputStream zu 'schreiben', 
+ * moeglicherweise, weil auf dem Raspberry Pi das VLC als Kommando-
+ * zeilenprogramm ohne UI laeuft. Im Augenblick gelingt nur die Steuerung 
+ * ueber dbus. Hier muss noch geprueft werden, ob das auch mit Windows und 
+ * Mac OS klappt, was aber fuer einen Einsatz auf dem Raspberry Pi 
+ * nebensaechlich ist.
  * 
- * Im Augenblick gelingt nur die Steuerung ueber dbus. 
- * 
- * Hier muss noch geprueft werden, ob das auch mit Windows und 
- * Mac OS klappt.
+ * Die Steuerung von VLC via dbus wiederum folgt dem Standard mpris 
+ * (Media Player Remote Interfacing Specification) von freedesktop.org, 
+ * der von zahlreichen Mediaplayern unterstuetzt wird.
  * 
  * @author Ulrich Hilger
  */
 public class DBusHandler extends CmdHandler {
+  
+  private static final Logger logger = Logger.getLogger(DBusHandler.class.getName());
 
   public DBusHandler(String cmd) {
     super(cmd);
@@ -25,7 +34,10 @@
   protected String process(HttpExchange t, String params) {
       String antwort;// = null;
     try {
-      StringBuilder kommando = new StringBuilder(cmd);
+      StringBuilder kommando = new StringBuilder();
+      kommando.append(VLCPlayer.DBUS_PREFIX);
+      kommando.append(cmd);
+      logger.log(Level.FINE, "kommando: {0}", kommando.toString());
       Process player_process = Runtime.getRuntime().exec(kommando.toString());
       antwort = "Kommando ausgefuehrt: " + kommando;
     } catch (IOException ex) {
@@ -33,5 +45,4 @@
     }
     return antwort;
   }
-  
 }
diff --git a/src/de/uhilger/calypso/handler/VLCPlayer.java b/src/de/uhilger/calypso/handler/VLCPlayer.java
index 82a495e..a450b81 100644
--- a/src/de/uhilger/calypso/handler/VLCPlayer.java
+++ b/src/de/uhilger/calypso/handler/VLCPlayer.java
@@ -22,7 +22,9 @@
   private static final Logger logger = Logger.getLogger(VLCPlayer.class.getName());
 
   public static final String CMD_STOP = "s";
-  public static final String CMD_PAUSE_RESUME = "dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2   org.mpris.MediaPlayer2.Player.PlayPause";
+  public static final String DBUS_PREFIX = "dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2   org.mpris.MediaPlayer2.Player.";
+  public static final String CMD_PAUSE_RESUME = "PlayPause";
+  public static final String CMD_SEEK = "Seek";
 
   @Override
   public String abspielen(String urlStr, String parameter, String meldeUrlStr, String token) {
diff --git a/src/de/uhilger/calypso/handler/VLCSeekHandler.java b/src/de/uhilger/calypso/handler/VLCSeekHandler.java
new file mode 100644
index 0000000..2ca4c19
--- /dev/null
+++ b/src/de/uhilger/calypso/handler/VLCSeekHandler.java
@@ -0,0 +1,61 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package de.uhilger.calypso.handler;
+
+import com.sun.net.httpserver.HttpExchange;
+import de.uhilger.calypso.App;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2   org.mpris.MediaPlayer2.Player.Seek int64:-5000000
+ * 
+ * @author Ulrich Hilger
+ */
+public class VLCSeekHandler extends CmdHandler {
+  
+  private static final Logger logger = Logger.getLogger(VLCSeekHandler.class.getName());
+  
+  public VLCSeekHandler(String cmd) {
+    super(cmd);
+  }
+  
+  @Override
+  protected String process(HttpExchange t, String params) {
+      String antwort;// = null;
+    try {
+      StringBuilder kommando = new StringBuilder();
+      kommando.append(VLCPlayer.DBUS_PREFIX);
+      kommando.append(cmd);
+      kommando.append(params);
+      logger.log(Level.FINE, "kommando: {0}", kommando.toString());
+      Process player_process = Runtime.getRuntime().exec(kommando.toString());
+      antwort = "Kommando ausgefuehrt: " + kommando;
+    } catch (IOException ex) {
+      antwort = "Fehler: " + ex.getMessage();
+    }
+    return antwort;
+  }
+  
+  @Override
+  protected StringBuilder buildParams(HttpExchange t) {
+    Player player = App.getPlayer();
+    StringBuilder params = super.buildParams(t);
+    
+    if(player instanceof VLCPlayer) {
+      String pos = player.getParam(map, "pos");
+      if(!pos.isEmpty()) {
+        params.append(" ");
+        params.append("int64:");
+        params.append(pos);
+        params.append("000000"); // Mikrosekunden
+      }
+    }
+    
+    logger.log(Level.FINER, "params: " + params.toString());
+    return params;
+  } 
+}

--
Gitblit v1.9.3