commit | author | age
|
60719c
|
1 |
/* |
aaed2d
|
2 |
Calypso - Media Player Remote Control via HTTP for Raspberry Pi |
U |
3 |
Copyright (C) 2021-2023 Ulrich Hilger |
60719c
|
4 |
|
U |
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
229976
|
19 |
package de.uhilger.calypso; |
8e2038
|
20 |
|
229976
|
21 |
import de.uhilger.calypso.handler.OMXPlayer; |
U |
22 |
import de.uhilger.calypso.handler.Player; |
|
23 |
import de.uhilger.calypso.handler.VLCPlayer; |
8e2038
|
24 |
import java.io.IOException; |
U |
25 |
import java.util.HashMap; |
|
26 |
import java.util.logging.Level; |
|
27 |
import java.util.logging.Logger; |
|
28 |
|
|
29 |
/** |
aaed2d
|
30 |
* Hauptklasse von Calypso |
cc2a32
|
31 |
* |
aaed2d
|
32 |
* Aufruf mit<br> |
U |
33 |
* java -jar calypso.jar port=9000 ctx="/calypso"<br> |
|
34 |
* java -jar calypso.jar nfs-prefix="/media/mc" port=9000<br> |
|
35 |
* java -Djava.util.logging.config.file=logging.properties -jar ..<br> |
cc2a32
|
36 |
* |
U |
37 |
* Der Parameter nfs-prefix bewirkt, dass beim Abspielen relative Pfade |
|
38 |
* mit diesem Praefix verbunden werden und setzt voraus, dass auf der |
aaed2d
|
39 |
* Maschine ein NFS-Mount ueber /etc/fstab eingerichtet ist.<br> |
U |
40 |
* <br> |
|
41 |
* Anmerkung anlaesslich der Aenderung auf VLC (2.1.2023):<br> |
|
42 |
* Mit Calypso wurde erstmals jdk.httpserver anstelle von Tomcat |
|
43 |
* einsetzt. Es war in diesem Punkt noch ein Laborversuch und sollte |
|
44 |
* unter Wiederverwendung der wesentlichen Teile bei Gelegenheit |
|
45 |
* neu gebaut werden. |
cc2a32
|
46 |
* |
aaed2d
|
47 |
* @author Ulrich Hilger |
U |
48 |
* @version 0.2 vom 2.1.2023, 0.1 vom 20.03.2021 als Nachfolger von Pirc (02.2013-03.2021) |
8e2038
|
49 |
*/ |
U |
50 |
public class App { |
|
51 |
|
|
52 |
private static final Logger logger = Logger.getLogger(App.class.getName()); |
|
53 |
|
ac1194
|
54 |
public static final String IP_PORT = "port"; |
U |
55 |
public static final String IP_WWW_DATA = "www-data"; |
|
56 |
public static final String IP_NFS_PREFIX = "nfs-prefix"; |
cfe367
|
57 |
public static final String IP_PLAYER = "player"; |
U |
58 |
public static final String VLC_PLAYER = "vlc"; |
|
59 |
public static final String OMX_PLAYER = "omx"; |
6ff352
|
60 |
public static final String OMX_WD = "omx.wd"; |
c2c1fd
|
61 |
public static final String CTX = "ctx"; |
cfe367
|
62 |
|
c2c1fd
|
63 |
public static final String DEFAULT_CTX = "/calypso"; |
ac1194
|
64 |
|
0af362
|
65 |
private static HashMap initParams; |
a7f0a1
|
66 |
private static Process playerproc; |
cfe367
|
67 |
private static Player player; |
a7f0a1
|
68 |
|
8e2038
|
69 |
/** |
U |
70 |
* @param args the command line arguments |
|
71 |
*/ |
|
72 |
public static void main(String[] args) { |
|
73 |
initParams = new HashMap(); |
|
74 |
for(String arg: args) { |
|
75 |
String[] argParts = arg.split("="); |
|
76 |
initParams.put(argParts[0], argParts[1]); |
|
77 |
} |
ac1194
|
78 |
|
cfe367
|
79 |
String playerType = getInitParameter(IP_PLAYER); |
U |
80 |
switch(playerType) { |
|
81 |
case VLC_PLAYER: |
|
82 |
player = new VLCPlayer(); |
|
83 |
break; |
|
84 |
case OMX_PLAYER: |
|
85 |
player = new OMXPlayer(); |
|
86 |
break; |
|
87 |
} |
ac1194
|
88 |
Server server = new Server(Integer.parseInt(getInitParameter(IP_PORT))); |
c2c1fd
|
89 |
String ctx = getInitParameter(CTX); |
U |
90 |
if(ctx != null && ctx.length() > 0) { |
|
91 |
server.setContextName(ctx); |
|
92 |
} else { |
|
93 |
server.setContextName(DEFAULT_CTX); |
|
94 |
} |
8e2038
|
95 |
try { |
b16b54
|
96 |
server.start(playerType); |
8e2038
|
97 |
} catch (IOException ex) { |
U |
98 |
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
public static void stop() { |
|
103 |
System.exit(0); |
|
104 |
} |
|
105 |
|
|
106 |
public static String getInitParameter(String pname) { |
|
107 |
String param = null; |
|
108 |
Object o = initParams.get(pname); |
|
109 |
if(o != null) { |
|
110 |
param = o.toString(); |
|
111 |
} |
|
112 |
return param; |
|
113 |
} |
|
114 |
|
a7f0a1
|
115 |
public static Process getPlayerProcess() { |
U |
116 |
return playerproc; |
|
117 |
} |
8e2038
|
118 |
|
a7f0a1
|
119 |
public static void setPlayerProcess(Process p) { |
U |
120 |
playerproc = p; |
|
121 |
} |
cfe367
|
122 |
|
U |
123 |
public static Player getPlayer() { |
|
124 |
return player; |
|
125 |
} |
|
126 |
|
|
127 |
public static void setPlayer(Player pl) { |
|
128 |
player = pl; |
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
|
8e2038
|
133 |
} |