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/>. |
|
17 |
*/ |
|
18 |
|
8e2038
|
19 |
package de.uhilger.avdirektor; |
U |
20 |
|
|
21 |
import com.sun.net.httpserver.HttpServer; |
cc2a32
|
22 |
import de.uhilger.avdirektor.handler.CmdHandler; |
ac1194
|
23 |
import de.uhilger.avdirektor.handler.FileHandler; |
0af362
|
24 |
import de.uhilger.avdirektor.handler.OMXPlayer; |
0c8d27
|
25 |
import de.uhilger.avdirektor.handler.PingHandler; |
8e2038
|
26 |
import de.uhilger.avdirektor.handler.PlayHandler; |
cfe367
|
27 |
import de.uhilger.avdirektor.handler.Player; |
852f20
|
28 |
import de.uhilger.avdirektor.handler.SeekHandler; |
8e2038
|
29 |
import de.uhilger.avdirektor.handler.StopServerHandler; |
cfe367
|
30 |
import de.uhilger.avdirektor.handler.VLCPlayer; |
8e2038
|
31 |
import java.io.IOException; |
U |
32 |
import java.util.logging.Logger; |
|
33 |
import java.net.InetSocketAddress; |
cd1557
|
34 |
import java.util.concurrent.Executors; |
8e2038
|
35 |
|
U |
36 |
/** |
|
37 |
* |
|
38 |
* @author ulrich |
|
39 |
*/ |
|
40 |
public class Server { |
|
41 |
|
|
42 |
private static final Logger logger = Logger.getLogger(Server.class.getName()); |
|
43 |
|
|
44 |
private int port; |
|
45 |
|
|
46 |
public Server(int port) { |
|
47 |
this.port = port; |
|
48 |
} |
|
49 |
|
|
50 |
public void setPort(int port) { |
|
51 |
this.port = port; |
|
52 |
} |
|
53 |
|
|
54 |
public void start() throws IOException { |
|
55 |
logger.info("Server starting on port " + port); |
0c8d27
|
56 |
|
8e2038
|
57 |
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); |
0af362
|
58 |
server.createContext("/avd/play", new PlayHandler(OMXPlayer.F_PLAY)); |
U |
59 |
server.createContext("/avd/seek", new SeekHandler(OMXPlayer.F_SEEK)); |
|
60 |
server.createContext("/avd/stop", new CmdHandler(OMXPlayer.CMD_STOP)); |
|
61 |
server.createContext("/avd/pause", new CmdHandler(OMXPlayer.CMD_PAUSE_RESUME)); |
|
62 |
server.createContext("/avd/ping", new PingHandler(OMXPlayer.F_PING)); |
8e2038
|
63 |
server.createContext("/avd/server/stop", new StopServerHandler()); |
ac1194
|
64 |
server.createContext("/avd/ui", new FileHandler(App.getInitParameter(App.IP_WWW_DATA))); |
cd1557
|
65 |
//server.setExecutor(null); // creates a default executor |
U |
66 |
server.setExecutor(Executors.newFixedThreadPool(20)); |
8e2038
|
67 |
server.start(); |
cfe367
|
68 |
} |
8e2038
|
69 |
|
U |
70 |
} |