commit | author | age
|
929228
|
1 |
/* |
U |
2 |
Calypso - Media Player Remote Control via HTTP for Raspberry Pi |
|
3 |
Copyright (C) 2021-2023 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 |
|
e27ab1
|
19 |
package de.uhilger.calypso.actor; |
929228
|
20 |
|
e27ab1
|
21 |
import de.uhilger.calypso.MeldeThread; |
U |
22 |
import de.uhilger.calypso.Rueckmelder; |
|
23 |
import de.uhilger.calypso.http.Server; |
929228
|
24 |
import java.io.IOException; |
U |
25 |
import java.util.Map; |
|
26 |
import java.util.logging.Level; |
|
27 |
import java.util.logging.Logger; |
|
28 |
|
|
29 |
/** |
|
30 |
* Der PlayActor loest das Abspielen eines Titels aus. |
|
31 |
* |
|
32 |
* Das koennte auch als Shell-Skript geschehen, aber abhaengig |
|
33 |
* vom verwendeten Abspielprogramm benoetigt man das Prozessobjekt |
|
34 |
* des laufenden Abspielprozesses im Verlauf des Abspielens noch, um |
|
35 |
* weitere Kommandos zu senden. |
|
36 |
* |
|
37 |
* Beim Abspieler mpv werden Kommandos allerdings ueber Unix Domain |
|
38 |
* Sockets gesendet, hierfuer waere also das Objekt des laufenden |
|
39 |
* Abspielprozesses nicht noetig. Man benoetigt es aber auch um |
|
40 |
* festzustellen, ob der Abspielprozess beendet ist. |
|
41 |
* |
|
42 |
* @author Ulrich Hilger |
|
43 |
*/ |
|
44 |
public class PlayActor { |
|
45 |
|
|
46 |
public Process run(Map parameter) { |
|
47 |
String meldeUrlStr = null; |
|
48 |
Object o = parameter.get("r"); |
|
49 |
if (o instanceof String) { |
|
50 |
meldeUrlStr = (String) o; |
|
51 |
} |
|
52 |
|
|
53 |
StringBuilder kommando = new StringBuilder(); |
|
54 |
o = parameter.get("titel"); |
|
55 |
if (o instanceof String) { |
|
56 |
String titel = (String) o; |
81530d
|
57 |
kommando.append("mpv --input-ipc-server=/tmp/mpvsocket --no-terminal --no-sub "); |
929228
|
58 |
if (titel.toLowerCase().endsWith(".mp3")) { |
933ccd
|
59 |
kommando.append("--vo=null "); |
929228
|
60 |
} |
U |
61 |
kommando.append(titel); |
|
62 |
Logger.getLogger(PlayActor.class.getName()).log(Level.FINE, kommando.toString()); |
|
63 |
Process player_process; |
|
64 |
try { |
|
65 |
player_process = Runtime.getRuntime().exec(kommando.toString()); |
|
66 |
if (meldeUrlStr != null) { |
|
67 |
MeldeThread mt = new MeldeThread(); |
|
68 |
mt.setProcess(player_process); |
|
69 |
mt.lauscherHinzufuegen(new Rueckmelder()); |
|
70 |
mt.setMeldeUrl(meldeUrlStr); |
|
71 |
mt.start(); |
|
72 |
} |
|
73 |
return player_process; |
|
74 |
} catch (IOException ex) { |
|
75 |
Logger logger = Logger.getLogger(PlayActor.class.getName()); |
|
76 |
logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex); |
|
77 |
ex.printStackTrace(); |
|
78 |
return null; |
|
79 |
} |
|
80 |
} else { |
|
81 |
Logger.getLogger(PlayActor.class.getName()).log(Level.INFO, "Titel fehlt"); |
|
82 |
return null; |
|
83 |
} |
|
84 |
} |
|
85 |
} |