Переглянути джерело

first iteration of the "hostside" part of JukeboxRemote

LH 6 роки тому
батько
коміт
9f01a87608

+ 5 - 1
iZpl/build.gradle

@@ -101,7 +101,11 @@ distZip {
   }
 }
 
-
+task apiJar(type: Jar, dependsOn: compileJava) {
+ baseName = project.name + '-apistub'
+ from sourceSets.main.output.classesDir
+ include '**/iZpl/API/*'
+}
 
 
 

+ 75 - 0
iZplPlugins/JukeBox/src/main/java/de/nplusc/izc/izpl/plugins/jukebox/APIWrapper.java

@@ -0,0 +1,75 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package de.nplusc.izc.izpl.plugins.jukebox;
+
+import de.nplusc.izc.iZpl.API.UIPlugin;
+import java.awt.Image;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import javax.imageio.ImageIO;
+
+/**
+ * Wrapping class to avoid linking against the main API class. Required for standalone mode.
+ * @author tgoerner
+ */
+public class APIWrapper
+{
+    public static UIPlugin getUiPlugin()
+    {
+        try
+        {
+            Class c = Class.forName("de.nplusc.izc.iZpl.API.IZPLApi");
+            Method m = c.getMethod("getUIPlugin", (Class) null);
+            
+            return (UIPlugin) m.invoke(null, null);
+        }
+        catch(ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored)
+        {
+            return null;
+        }
+    }
+    
+    public static Image getProgramIcon()
+    {
+        try
+        {
+            Class c = Class.forName("de.nplusc.izc.iZpl.API.IZPLApi");
+            Method m = c.getMethod("getProgramIcon", (Class) null);
+            
+            return (Image) m.invoke(null, null);
+        }
+        catch(ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored)
+        {
+            try
+            {
+                return ImageIO.read(APIWrapper.class.getResource("/fallbackIcon.png"));
+            } catch (IOException ex)
+            {
+                return null;
+            }
+        }
+    }
+    
+    public static void quickQuit()
+    {
+        try
+        {
+            Class c = Class.forName("de.nplusc.izc.iZpl.API.IZPLApi");
+            Method m = c.getMethod("quickQuitWithoutSaving", (Class) null);
+            
+            m.invoke(null, (Object) null);
+        }
+        catch(ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored)
+        {
+            //only legit case inside here.
+            System.exit(0);
+        }
+    }
+    
+    
+    
+}

+ 10 - 4
iZplPlugins/JukeBox/src/main/java/de/nplusc/izc/izpl/plugins/jukebox/JukeBox.java

@@ -6,7 +6,6 @@
 package de.nplusc.izc.izpl.plugins.jukebox;
 
 import de.nplusc.izc.iZpl.API.FeaturePlugin;
-import de.nplusc.izc.iZpl.API.IZPLApi;
 import de.nplusc.izc.iZpl.API.UIPlugin;
 import de.nplusc.izc.iZpl.API.shared.InvalidPlayListFileException;
 import de.nplusc.izc.tools.baseTools.Detectors;
@@ -249,7 +248,7 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
     @Override
     public void initializePlugin()
     {
-        if(IZPLApi.getUIPlugin()==this)
+        if(APIWrapper.getUiPlugin()==this)
         {
             l.info("Init UI(JukeBox)");
             jukeboxBackend= new LocalBackend(this);
@@ -302,7 +301,7 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
             if(recovery)
             {
                 l.error("Serious statefile corruption detected");
-                IZPLApi.quickQuitWithoutSaving(); //this should not happen at all on remote
+                APIWrapper.quickQuit();//this should not happen at all on remote
             }
             //reloading data from disk and flushing internal references when the resume state got corrupted from a encoding change
             jukeboxBackend.reload();
@@ -414,7 +413,7 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
             setUndecorated(true);
             setLocation(0, 0);
         }
-        setIconImage(IZPLApi.getProgramIcon());
+        setIconImage(APIWrapper.getProgramIcon());
         initComponents();
         JLabel tmp = new JLabel("  "); //HACK incoming
         tmp.setMinimumSize(new Dimension(30, 30));
@@ -579,6 +578,13 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
     {
         refreshScheduledItemList();
     }
+
+    @Override
+    public void setPlayStatus(boolean playing)
+    {
+        this.playing = playing;
+        btnPlayPause.setText(playing?"Pause":"play");
+    }
     
     
 }

+ 19 - 3
iZplPlugins/JukeBox/src/main/java/de/nplusc/izc/izpl/plugins/jukebox/JukeboxClientHandler.java

@@ -24,6 +24,7 @@ import java.io.InputStreamReader;
 import java.io.PrintStream;
 import java.net.Socket;
 import java.util.HashMap;
+import java.util.List;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.yaml.snakeyaml.Yaml;
@@ -114,6 +115,8 @@ public class JukeboxClientHandler
     }
     private void parsePacket(Packet p)
     {
+
+        
         HashMap<String,Object> packet = p.getData();
         String commandType = (String) packet.get("COMMAND");
         String param = (String) packet.get("PARAM");
@@ -155,7 +158,15 @@ public class JukeboxClientHandler
             {
                 try
                 {
-                    srv.getTitles();
+                    String[] titles = srv.getTitles();
+                    HashMap<String,Object> data = new HashMap<>();
+                    Packet response = new Packet();
+                    data.put("RESPONSE", "TITLES");
+                    data.put("DATA", titles);
+                    response.setData(data);
+                    respondToLinkedClient(response);
+                    
+                    
                 }
                 catch (InvalidPlayListFileException ex)
                 {
@@ -164,8 +175,13 @@ public class JukeboxClientHandler
             }
             break;
             case "getScheduled":
-                srv.getScheduledTracks();
-                
+                List<String> titles = srv.getScheduledTracks();
+                HashMap<String,Object> data = new HashMap<>();
+                Packet response = new Packet();
+                data.put("RESPONSE", "TITLES");
+                data.put("DATA", titles);
+                response.setData(data);
+                respondToLinkedClient(response);
             default:
                 break;
         }

+ 22 - 6
iZplPlugins/JukeBox/src/main/java/de/nplusc/izc/izpl/plugins/jukebox/JukeboxServer.java

@@ -17,10 +17,12 @@
 package de.nplusc.izc.izpl.plugins.jukebox;
 
 import de.nplusc.izc.iZpl.API.shared.InvalidPlayListFileException;
+import de.nplusc.izc.iZpl.API.shared.networking.Packet;
 import java.io.IOException;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -74,39 +76,53 @@ public class JukeboxServer implements PlaybackStatusUpdater,Backend
     
     
     
+    private void sendUpdate(String action,String value)
+    {
+        HashMap<String,Object> data = new HashMap<>();
+        final Packet response = new Packet();
+        data.put("RESPONSE", "UPDATE");
+        data.put("TOPIC", action);
+        data.put("VALUE", value);
+        response.setData(data);
+        currentClients.forEach((c->c.respondToLinkedClient(response)));
+    }
     
     
     
-    
+    @Override
+    public void setPlayStatus(boolean playing)
+    {
+        sendUpdate("PLAYING", playing+"");
+    }
     
     @Override
     public void updateTrackLength(int length)
     {
-        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+        sendUpdate("LENGTH", length+"");
     }
 
     @Override
     public void updateTrackTitle(String title)
     {
-        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+        sendUpdate("TITLE", title+"");
     }
 
     @Override
     public void updateCurrentPlaybackPosition(int position)
     {
-        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+        sendUpdate("POSTITION",position+"");
     }
 
     @Override
     public void triggerTableRefresh()
     {
-        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+        sendUpdate("TRACKS", "");
     }
 
     @Override
     public void triggerScheduleRefresh()
     {
-        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+        sendUpdate("QUEUE", "");
     }
 
     

+ 1 - 0
iZplPlugins/JukeBox/src/main/java/de/nplusc/izc/izpl/plugins/jukebox/PlaybackStatusUpdater.java

@@ -27,4 +27,5 @@ public interface PlaybackStatusUpdater
     void updateCurrentPlaybackPosition(int position);
     void triggerTableRefresh();
     void triggerScheduleRefresh();
+    void setPlayStatus(boolean playing);
 }

+ 64 - 1
iZplPlugins/JukeBox/src/main/java/de/nplusc/izc/izpl/plugins/jukebox/RemoteBackend.java

@@ -16,11 +16,74 @@
  */
 package de.nplusc.izc.izpl.plugins.jukebox;
 
+import de.nplusc.izc.iZpl.API.shared.InvalidPlayListFileException;
+import java.util.List;
+
 /**
  *
  * @author iZc <nplusc.de>
  */
-public class RemoteBackend
+public class RemoteBackend implements Backend
 {
+
+    @Override
+    public void play()
+    {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public void pause()
+    {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public void seek(int pos)
+    {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public void initBackend()
+    {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public void skip()
+    {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public void enqueue(int index)
+    {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public void reload()
+    {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public String[] getTitles() throws InvalidPlayListFileException
+    {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public List<String> getScheduledTracks()
+    {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public void quitWithSave()
+    {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
     
 }

BIN
iZplPlugins/JukeBox/src/main/resources/fallbackIcon.png