commit | author | age
|
60719c
|
1 |
/* |
U |
2 |
AV-Direktor - Control OMXPlayer on Raspberry Pi via HTTP |
|
3 |
Copyright (C) 2021 Ulrich Hilger |
|
4 |
|
|
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/>. |
b16b54
|
17 |
*/ |
229976
|
18 |
package de.uhilger.calypso; |
8e2038
|
19 |
|
U |
20 |
import com.sun.net.httpserver.HttpServer; |
b16b54
|
21 |
import de.uhilger.calypso.handler.BasePlayer; |
229976
|
22 |
import de.uhilger.calypso.handler.CmdHandler; |
b16b54
|
23 |
import de.uhilger.calypso.handler.DBusHandler; |
229976
|
24 |
import de.uhilger.calypso.handler.FileHandler; |
U |
25 |
import de.uhilger.calypso.handler.LogHandler; |
|
26 |
import de.uhilger.calypso.handler.OMXPlayer; |
|
27 |
import de.uhilger.calypso.handler.PingHandler; |
|
28 |
import de.uhilger.calypso.handler.PlayHandler; |
|
29 |
import de.uhilger.calypso.handler.PlayOnHandler; |
|
30 |
import de.uhilger.calypso.handler.SeekHandler; |
|
31 |
import de.uhilger.calypso.handler.StopServerHandler; |
b16b54
|
32 |
import de.uhilger.calypso.handler.VLCKillHandler; |
U |
33 |
import de.uhilger.calypso.handler.VLCPlayer; |
8e2038
|
34 |
import java.io.IOException; |
U |
35 |
import java.util.logging.Logger; |
|
36 |
import java.net.InetSocketAddress; |
cd1557
|
37 |
import java.util.concurrent.Executors; |
b16b54
|
38 |
import java.util.logging.Level; |
8e2038
|
39 |
|
U |
40 |
/** |
|
41 |
* |
|
42 |
* @author ulrich |
|
43 |
*/ |
|
44 |
public class Server { |
b16b54
|
45 |
|
8e2038
|
46 |
private static final Logger logger = Logger.getLogger(Server.class.getName()); |
U |
47 |
|
|
48 |
private int port; |
b16b54
|
49 |
|
c2c1fd
|
50 |
private String contextName; |
b16b54
|
51 |
|
8e2038
|
52 |
public Server(int port) { |
U |
53 |
this.port = port; |
|
54 |
} |
b16b54
|
55 |
|
8e2038
|
56 |
public void setPort(int port) { |
U |
57 |
this.port = port; |
|
58 |
} |
b16b54
|
59 |
|
c2c1fd
|
60 |
/** |
b16b54
|
61 |
* |
c2c1fd
|
62 |
* @param contextName e.g. '/calypso' or '/cal' |
U |
63 |
*/ |
|
64 |
public void setContextName(String contextName) { |
|
65 |
this.contextName = contextName; |
|
66 |
} |
b16b54
|
67 |
|
U |
68 |
public void start(String playerType) throws IOException { |
|
69 |
logger.log(Level.INFO, "Server starting on port {0}", port); |
0c8d27
|
70 |
|
8e2038
|
71 |
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); |
b16b54
|
72 |
server.createContext(contextName + "/play", new PlayHandler(BasePlayer.F_PLAY)); |
U |
73 |
if (playerType.equals(App.OMX_PLAYER)) { |
|
74 |
server.createContext(contextName + "/seek", new SeekHandler(OMXPlayer.F_SEEK)); |
|
75 |
server.createContext(contextName + "/stop", new CmdHandler(OMXPlayer.CMD_STOP)); |
|
76 |
server.createContext(contextName + "/pause", new CmdHandler(OMXPlayer.CMD_PAUSE_RESUME)); |
|
77 |
server.createContext(contextName + "/vol-inc", new CmdHandler(OMXPlayer.CMD_INC_VOL)); |
|
78 |
server.createContext(contextName + "/vol-dec", new CmdHandler(OMXPlayer.CMD_DEC_VOL)); |
|
79 |
server.createContext(contextName + "/info", new CmdHandler(OMXPlayer.CMD_TOGGLE_INFO)); |
|
80 |
server.createContext(contextName + "/log", new LogHandler()); |
|
81 |
server.createContext(contextName + "/playon", new PlayOnHandler(OMXPlayer.F_PLAY_ON)); |
|
82 |
} else if (playerType.equals(App.VLC_PLAYER)) { |
|
83 |
server.createContext(contextName + "/play", new PlayHandler(BasePlayer.F_PLAY)); |
|
84 |
//server.createContext(contextName + "/stop", new CmdHandler(VLCPlayer.CMD_STOP)); |
|
85 |
server.createContext(contextName + "/pause", new DBusHandler(VLCPlayer.CMD_PAUSE_RESUME)); |
|
86 |
server.createContext(contextName + "/stop", new VLCKillHandler()); |
|
87 |
|
|
88 |
} |
c2c1fd
|
89 |
server.createContext(contextName + "/ui", new FileHandler(App.getInitParameter(App.IP_WWW_DATA))); |
b16b54
|
90 |
server.createContext(contextName + "/ping", new PingHandler(BasePlayer.F_PING)); |
U |
91 |
server.createContext(contextName + "/server/stop", new StopServerHandler()); |
cd1557
|
92 |
//server.setExecutor(null); // creates a default executor |
U |
93 |
server.setExecutor(Executors.newFixedThreadPool(20)); |
8e2038
|
94 |
server.start(); |
b16b54
|
95 |
} |
8e2038
|
96 |
|
U |
97 |
} |