/*
|
Calypso - Media Player Remote Control via HTTP for Raspberry Pi
|
Copyright (C) 2021-2023 Ulrich Hilger
|
|
This program is free software: you can redistribute it and/or modify
|
it under the terms of the GNU Affero General Public License as
|
published by the Free Software Foundation, either version 3 of the
|
License, or (at your option) any later version.
|
|
This program is distributed in the hope that it will be useful,
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
GNU Affero General Public License for more details.
|
|
You should have received a copy of the GNU Affero General Public License
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
*/
|
|
package de.uhilger.calypso.actor;
|
|
import de.uhilger.calypso.MeldeThread;
|
import de.uhilger.calypso.Rueckmelder;
|
import de.uhilger.calypso.http.Server;
|
import java.io.IOException;
|
import java.util.Map;
|
import java.util.logging.Level;
|
import java.util.logging.Logger;
|
|
/**
|
* Der PlayActor loest das Abspielen eines Titels aus.
|
*
|
* Das koennte auch als Shell-Skript geschehen, aber abhaengig
|
* vom verwendeten Abspielprogramm benoetigt man das Prozessobjekt
|
* des laufenden Abspielprozesses im Verlauf des Abspielens noch, um
|
* weitere Kommandos zu senden.
|
*
|
* Beim Abspieler mpv werden Kommandos allerdings ueber Unix Domain
|
* Sockets gesendet, hierfuer waere also das Objekt des laufenden
|
* Abspielprozesses nicht noetig. Man benoetigt es aber auch um
|
* festzustellen, ob der Abspielprozess beendet ist.
|
*
|
* @author Ulrich Hilger
|
*/
|
public class PlayActor {
|
|
public Process run(Map parameter) {
|
String meldeUrlStr = null;
|
Object o = parameter.get("r");
|
if (o instanceof String) {
|
meldeUrlStr = (String) o;
|
}
|
|
StringBuilder kommando = new StringBuilder();
|
o = parameter.get("titel");
|
if (o instanceof String) {
|
String titel = (String) o;
|
kommando.append("mpv --input-ipc-server=/tmp/mpvsocket --no-terminal ");
|
if (titel.toLowerCase().endsWith(".mp3")) {
|
kommando.append("--vo=null ");
|
}
|
kommando.append(titel);
|
Logger.getLogger(PlayActor.class.getName()).log(Level.FINE, kommando.toString());
|
Process player_process;
|
try {
|
player_process = Runtime.getRuntime().exec(kommando.toString());
|
if (meldeUrlStr != null) {
|
MeldeThread mt = new MeldeThread();
|
mt.setProcess(player_process);
|
mt.lauscherHinzufuegen(new Rueckmelder());
|
mt.setMeldeUrl(meldeUrlStr);
|
mt.start();
|
}
|
return player_process;
|
} catch (IOException ex) {
|
Logger logger = Logger.getLogger(PlayActor.class.getName());
|
logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
|
ex.printStackTrace();
|
return null;
|
}
|
} else {
|
Logger.getLogger(PlayActor.class.getName()).log(Level.INFO, "Titel fehlt");
|
return null;
|
}
|
}
|
}
|