/* Mediazentrale - Personal Media Center Copyright (C) 2021 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 . */ package de.uhilger.mediaz.api; import com.sun.net.httpserver.HttpExchange; import de.uhilger.mediaz.App; import de.uhilger.mediaz.Server; import de.uhilger.mediaz.entity.Abspieler; import de.uhilger.mediaz.entity.Abspielliste; import de.uhilger.mediaz.entity.Entity; import de.uhilger.mediaz.entity.Titel; import de.uhilger.mediaz.store.FileStorage; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Logger; /** * Die MediaSteuerung verarbeitet HTTP-Signale zur Steuerung von Media-Operationen * wie z.B. dem Spielen einer Abspielliste oder dem Starten oder Stoppen eines Videos * auf einem entfernten Abspielgeraet. * * HTTP GET /mz/api/strg/abspieler/play/liste/[name] * HTTP GET /mz/api/strg/abspieler/play/[titel-url] * HTTP GET /mz/api/strg/abspieler/pause * HTTP GET /mz/api/strg/abspieler/stop * HTTP GET /mz/api/strg/abspieler/weiter * * * @author Ulrich Hilger * @version 1, 9.4.2021 */ public class MediaSteuerung extends AbstractHandler { private static final Logger logger = Logger.getLogger(MediaSteuerung.class.getName()); private Map spielt = new HashMap(); @Override protected String get(HttpExchange e) { String response = "in Arbeit.."; String path = e.getRequestURI().toString(); String[] elems = path.split(App.getRs(Server.RB_SLASH)); // 4 Player name, 7 listenname switch(elems.length) { case 8: response = play(e, elems[4], elems[7]); break; } return response; } @Override protected String put(HttpExchange e) throws IOException { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override protected String post(HttpExchange e) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override protected boolean delete(HttpExchange e) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } private String play(HttpExchange e, String aName, String lName) { FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); Entity entity = fs.read(FileStorage.ST_ABSPIELER, aName); if(entity instanceof Abspieler) { Abspieler abspieler = (Abspieler) entity; String aUrl = abspieler.getUrl(); entity = fs.read(FileStorage.ST_ABSPIELLISTE, lName); if(entity instanceof Abspielliste) { Abspielliste liste = (Abspielliste) entity; Titel titel = liste.getTitel().get(0); spielt.put(aName, (int) 0); String titelUrl = titel.getKatalogUrl() + titel.getPfad() + titel.getName(); logger.info("abspielen von " + titelUrl + " auf " + aUrl); } } String response = "Abspielen der Liste " + lName + " auf Abspieler " + aName + " gestartet."; return response; } private String kommando() { return "avd/play?th=60&ti=60&o=local&titel="; } // rpi4-az:9090/avd/play?titel=/Filme/S/sound_city.m4v&th=60&ti=60&o=local // aUrl http://rpi4-wz:9090/ // titelUrl /media/test/A/The-Alan-Parsons-Project/I-Robot/02-I-Wouldnt-Want-to-Be-Like-You.mp3 }