commit | author | age
|
098eef
|
1 |
package de.uhilger.calypso.handler; |
U |
2 |
|
|
3 |
import com.sun.net.httpserver.HttpExchange; |
|
4 |
import de.uhilger.calypso.App; |
|
5 |
import de.uhilger.calypso.MeldeThread; |
|
6 |
import java.io.IOException; |
|
7 |
import java.util.Map; |
|
8 |
import java.util.logging.Level; |
|
9 |
import java.util.logging.Logger; |
|
10 |
|
|
11 |
/** |
|
12 |
* |
|
13 |
* @author ulrich |
|
14 |
*/ |
|
15 |
public class MPVPlayer extends BasePlayer implements Player { |
|
16 |
|
|
17 |
private static final Logger logger = Logger.getLogger(MPVPlayer.class.getName()); |
|
18 |
|
|
19 |
/* |
|
20 |
echo '{ "command": ["get_property", "playback-time"] }' | socat - /tmp/mpvsocket |
|
21 |
{"data":190.482000,"error":"success"} |
|
22 |
|
|
23 |
echo 'show-text ${playback-time}' | socat - /tmp/mpvsocket |
|
24 |
|
|
25 |
{ "command": ["set_property", "pause", true] } |
|
26 |
{ "error": "success" } |
|
27 |
|
|
28 |
{"command": ["cycle", "pause"]} |
|
29 |
|
|
30 |
*/ |
|
31 |
public static final String SOCK_PREFIX = ""; |
|
32 |
public static final String CMD_PAUSE_RESUME = "pause"; |
|
33 |
public static final String CMD_SEEK = "seek"; |
|
34 |
|
|
35 |
@Override |
|
36 |
public String abspielen(String urlStr, String parameter, String meldeUrlStr, String token) { |
|
37 |
String antwort;// = null; |
|
38 |
try { |
|
39 |
//Object o = t.getAttribute(App.PI_PLAYER); |
|
40 |
Process o = App.getPlayerProcess(); |
|
41 |
if(o != null) { |
|
42 |
tilgen(); |
|
43 |
} |
|
44 |
StringBuilder kommando = new StringBuilder("mpv --input-ipc-server=/tmp/mpvsocket --no-terminal "); |
|
45 |
/* |
|
46 |
if(parameter != null) { |
|
47 |
kommando.append(parameter); |
|
48 |
kommando.append(BLANK); |
|
49 |
} |
|
50 |
*/ |
|
51 |
if(urlStr.startsWith("http")) { |
|
52 |
kommando.append(urlStr.replace(" ", "%20")); |
|
53 |
kommando.append("?t="); |
|
54 |
kommando.append(token); |
|
55 |
} else { |
|
56 |
/* |
|
57 |
//url z.B.: Filme/H/HEAT_D2.m4v |
|
58 |
|
|
59 |
hier muss noch der Pfad hinzugefuegt werden, unter |
|
60 |
dem auf dem raspi die Datenquelle via NFS eingebunden ist, |
|
61 |
z.B. /media/mc/ |
|
62 |
dieser Teil des Pfades muss in pirc als Init-Parameter oder |
|
63 |
etwas aehnliches hinterlegt sein, weil es lokal zum jeweils |
|
64 |
verwendeten raspi gehoert |
|
65 |
|
|
66 |
*/ |
|
67 |
|
|
68 |
String pfad = App.getInitParameter("nfs-prefix"); |
|
69 |
kommando.append(pfad); |
|
70 |
|
|
71 |
kommando.append(urlStr); |
|
72 |
} |
|
73 |
//kommando.append(" vlc://quit"); |
|
74 |
logger.log(Level.FINE, "kommando: {0}", kommando.toString()); |
|
75 |
Process player_process = Runtime.getRuntime().exec(kommando.toString()); |
|
76 |
if(meldeUrlStr != null) { |
|
77 |
MeldeThread mt = new MeldeThread(); |
|
78 |
mt.setProcess(player_process); |
|
79 |
mt.lauscherHinzufuegen(this); |
|
80 |
mt.setMeldeUrl(meldeUrlStr); |
|
81 |
mt.start(); |
|
82 |
} |
|
83 |
//servletContext.setAttribute(App.PI_PLAYER, player_process); |
|
84 |
//t.setAttribute(App.PI_PLAYER, player_process); |
|
85 |
App.setPlayerProcess(player_process); |
|
86 |
//Runtime.getRuntime().exec("killall dbus-daemon"); |
|
87 |
antwort = "Abspielen gestartet, url: " + urlStr; |
|
88 |
} |
|
89 |
catch(IOException ex) { |
|
90 |
antwort = "Fehler: " + ex.getMessage(); |
|
91 |
} |
|
92 |
return antwort; |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
/* |
|
97 |
public String kommando(String k) { |
|
98 |
if(k.equalsIgnoreCase(VLCPlayer.CMD_STOP)) { |
|
99 |
Process p = App.getPlayerProcess(); |
|
100 |
p.destroy(); |
|
101 |
App.setPlayerProcess(null); |
|
102 |
} |
|
103 |
String antwort = "Kommando '" + k + "' ausgefuehrt."; |
|
104 |
return antwort; |
|
105 |
} |
|
106 |
*/ |
|
107 |
|
|
108 |
@Override |
|
109 |
public StringBuilder buildParams(HttpExchange t, Map m) { |
|
110 |
return new StringBuilder(); |
|
111 |
} |
|
112 |
|
|
113 |
|
|
114 |
} |