src/de/uhilger/tango/PlaylistListener.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/tango/Server.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/tango/api/ListHandler.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/tango/api/MediaSteuerung.java | ●●●●● patch | view | raw | blame | history | |
www/js/app.js | ●●●●● patch | view | raw | blame | history |
src/de/uhilger/tango/PlaylistListener.java
New file @@ -0,0 +1,9 @@ package de.uhilger.tango; /** * * @author Ulrich Hilger */ public interface PlaylistListener { public void titleRemoved(String listName, int titleIndex); } src/de/uhilger/tango/Server.java
@@ -121,9 +121,12 @@ server.createContext(ctx + rb.getString(RB_WEBROOT), new FileHandler(wwwDir.getAbsolutePath())); ablageorteEinklinken(server, rb, conf); server.createContext(ctx + rb.getString(RB_STORE), new StorageHandler(conf)); server.createContext(ctx + rb.getString(RB_STRG), new MediaSteuerung(conf)); MediaSteuerung ms = new MediaSteuerung(conf); server.createContext(ctx + rb.getString(RB_STRG), ms); server.createContext(ctx + rb.getString(RB_GSTRG), new GeraetSteuerung(conf)); server.createContext(ctx + rb.getString(RB_ALIST), new ListHandler(conf)); ListHandler lh = new ListHandler(conf); lh.addPlaylistListener(ms); server.createContext(ctx + rb.getString(RB_ALIST), lh); server.createContext(ctx + rb.getString(RB_STRM), new StreamHandler(conf)); server.createContext(ctx + rb.getString(RB_STOP_SERVER), new StopServerHandler()); //server.setExecutor(Executors.newFixedThreadPool(20)); src/de/uhilger/tango/api/ListHandler.java
@@ -20,12 +20,15 @@ import com.google.gson.Gson; import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.HttpExchange; import de.uhilger.tango.PlaylistListener; import de.uhilger.tango.Server; import de.uhilger.tango.entity.Abspielliste; import de.uhilger.tango.entity.Entity; import de.uhilger.tango.entity.Titel; import de.uhilger.tango.store.FileStorage; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.logging.Logger; @@ -58,8 +61,11 @@ private String conf; private List<PlaylistListener> listeners; public ListHandler(String conf) { this.conf = conf; listeners = new ArrayList(); } @Override @@ -242,7 +248,9 @@ if(titelStr.equalsIgnoreCase(ALLE_TITEL)) { liste.getTitel().clear(); } else { liste.getTitel().remove(Integer.parseInt(elems[elems.length-1])); int idx = Integer.parseInt(elems[elems.length-1]); liste.getTitel().remove(idx); sendRemovalInfo(liste.getName(), idx); } fs.write(liste, true); return true; @@ -251,4 +259,19 @@ } } private void sendRemovalInfo(String listName, int titleIndex) { Iterator<PlaylistListener> i = listeners.iterator(); while(i.hasNext()) { PlaylistListener l = i.next(); l.titleRemoved(listName, titleIndex); } } public void addPlaylistListener(PlaylistListener listener) { this.listeners.add(listener); } public void removePlaylistListener(PlaylistListener listener) { this.listeners.remove(listener); } } src/de/uhilger/tango/api/MediaSteuerung.java
@@ -19,6 +19,7 @@ import com.google.gson.Gson; import com.sun.net.httpserver.HttpExchange; import de.uhilger.tango.PlaylistListener; import de.uhilger.tango.Server; import de.uhilger.tango.entity.Abspielvorgang; import de.uhilger.tango.entity.Abspieler; @@ -31,8 +32,11 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -70,7 +74,7 @@ * @author Ulrich Hilger * @version 1, 9.4.2021 */ public class MediaSteuerung extends AbstractHandler { public class MediaSteuerung extends AbstractHandler implements PlaylistListener { private static final Logger logger = Logger.getLogger(MediaSteuerung.class.getName()); @@ -392,4 +396,26 @@ setReturnCode(code); return text; } /* ------- PlaylistListener implementation ------ */ @Override public void titleRemoved(String listName, int titleIndex) { Set keys = spielt.keySet(); Iterator<String> keyIterator = keys.iterator(); boolean found = false; while(keyIterator.hasNext() && !found) { String abspielerName = keyIterator.next(); Abspielvorgang av = (Abspielvorgang) spielt.get(abspielerName); if(av.getListe().equals(listName)) { found = true; int tnr = av.getTitelNr(); if(tnr > titleIndex) { av.setTitelNr(--tnr); logger.info("Abspieler " + abspielerName + " Liste " + av.getListe() + " titelnr jetzt " + tnr); spielt.put(abspielerName, av); } } } } } www/js/app.js
@@ -727,6 +727,11 @@ self.http_delete('api/alist/' + plname + '/' + index,'', function(responseText) { // DELETE http://localhost:9090/mz/api/alist/liste1/0 //self.meldung_mit_timeout(responseText, 1500); if(self.playingList === plname) { if(self.playingIndex > index) { --self.playingIndex; } } self.titel_liste(); });