commit | author | age
|
8e2038
|
1 |
package de.uhilger.avdirektor.handler; |
U |
2 |
|
|
3 |
import com.sun.net.httpserver.HttpExchange; |
|
4 |
import com.sun.net.httpserver.HttpHandler; |
|
5 |
import java.io.IOException; |
|
6 |
import java.io.OutputStream; |
e448af
|
7 |
import java.util.Map; |
8e2038
|
8 |
import java.util.logging.Level; |
U |
9 |
import java.util.logging.Logger; |
|
10 |
|
|
11 |
/** |
|
12 |
* |
|
13 |
* @author ulrich |
|
14 |
*/ |
|
15 |
public class PlayHandler extends OMXPlayer implements HttpHandler { |
|
16 |
|
|
17 |
private static final Logger logger = Logger.getLogger(PlayHandler.class.getName()); |
|
18 |
|
a7f0a1
|
19 |
/* |
cc2a32
|
20 |
rpi4-az:9090/avd/play?titel=/Filme/S/sound_city.m4v&th=60&ti=60&o=local |
a7f0a1
|
21 |
|
U |
22 |
OMXPlayer.abspielenMitParameternUndRueckmeldung( |
|
23 |
String urlStr, String parameter, String meldeUrlStr, String token) |
|
24 |
|
cc2a32
|
25 |
Parameter des Aufrufs play als query (th threshold, ti timeout) |
a7f0a1
|
26 |
|
U |
27 |
?titel=/Filme/S/sound_city.m4v |
|
28 |
&ti=60 |
|
29 |
&th=60 |
|
30 |
&o=local|hdmi|both |
|
31 |
&r=http://uhilger.de/mc/api/usw |
|
32 |
|
|
33 |
r muss ganz wegbleiben, wenn keine Rueckmeldung gewuescht ist |
|
34 |
|
|
35 |
*/ |
8e2038
|
36 |
@Override |
U |
37 |
public void handle(HttpExchange t) throws IOException { |
0c8d27
|
38 |
logger.log(Level.FINE, "RequestURI: {0}", t.getRequestURI().toString()); |
8e2038
|
39 |
|
a7f0a1
|
40 |
Map map = getQueryMap(t); |
U |
41 |
StringBuilder params = new StringBuilder(); |
|
42 |
params.append("-o "); |
|
43 |
params.append(getParam(map, "o")); |
|
44 |
params.append(" --threshold "); |
|
45 |
params.append(getParam(map, "th")); |
|
46 |
params.append(" --timeout "); |
|
47 |
params.append(getParam(map, "ti")); |
|
48 |
|
|
49 |
String antwort = abspielenMitParameternUndRueckmeldung( |
|
50 |
getParam(map, "titel"), params.toString(), getParam(map, "r"), "1"); |
0c8d27
|
51 |
|
U |
52 |
String response = getResponseString(map, "play", antwort); |
8e2038
|
53 |
t.sendResponseHeaders(200, response.length()); |
U |
54 |
OutputStream os = t.getResponseBody(); |
|
55 |
os.write(response.getBytes()); |
|
56 |
os.close(); |
|
57 |
} |
cc2a32
|
58 |
|
U |
59 |
|
8e2038
|
60 |
} |