Przeglądaj źródła

reworked of jzpl-jukebox to support network linking of UIs, loads as a FeaturePlugin for that mode

LH 6 lat temu
rodzic
commit
8da46b6a65

+ 1 - 1
iZpl/build.gradle

@@ -10,7 +10,7 @@ apply plugin: 'java'
 apply plugin: 'application'
 apply from: "$rootDir/utils/IO.gradle"
 
-version = '0.9.0.0'
+version = '0.10.0.0-snapshot'
 mainClassName = 'de.nplusc.izc.iZpl.Main'
 //'de.nplusc.izc.iZpl.Main'
 

+ 0 - 3
iZpl/src/main/java/de/nplusc/izc/iZpl/Utils/VlcInterface.java

@@ -40,7 +40,6 @@ import uk.co.caprica.vlcj.player.MediaPlayer;
 import uk.co.caprica.vlcj.player.MediaPlayerEventListener;
 import uk.co.caprica.vlcj.player.MediaPlayerFactory;
 import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
-import uk.co.caprica.vlcj.player.embedded.videosurface.CanvasVideoSurface;
 import uk.co.caprica.vlcj.runtime.RuntimeUtil;
 
 /**
@@ -759,8 +758,6 @@ public class VlcInterface implements PlaybackPlugin , MediaPlayerEventListener
             }
         }
     };
-    
-    
 }
            
     

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

@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2018 iZc
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package de.nplusc.izc.izpl.plugins.jukebox;
+
+import de.nplusc.izc.iZpl.API.shared.InvalidPlayListFileException;
+import java.util.List;
+
+/**
+ *
+ * @author iZc <nplusc.de>
+ */
+public interface Backend
+{
+    void play();
+    void pause();
+    void seek(int pos);
+    
+    void initBackend();
+    void skip();
+    
+    void enqueue(int index);
+    
+    void reload();
+    
+    String[] getTitles() throws InvalidPlayListFileException;
+    List<String> getScheduledTracks();
+    
+    /**
+     * Wrapper to the correct quitting method depending on the Backend used.
+     */
+    void quitWithSave();
+}

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

@@ -3,9 +3,6 @@
 <Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
   <Properties>
     <Property name="defaultCloseOperation" type="int" value="3"/>
-    <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
-      <Dimension value="[480, 800]"/>
-    </Property>
   </Properties>
   <SyntheticProperties>
     <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
@@ -94,11 +91,9 @@
           <Properties>
             <Property name="autoCreateRowSorter" type="boolean" value="true"/>
             <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor" postCode="tblPLE.setColumnModel (new HidableTableColumnModel(tblPLE.getColumnModel()));">
-              <Table columnCount="4" rowCount="4">
+              <Table columnCount="2" rowCount="4">
                 <Column editable="false" title="ID" type="java.lang.Object"/>
                 <Column editable="false" title="Title" type="java.lang.Object"/>
-                <Column editable="false" title="# to play" type="java.lang.Object"/>
-                <Column editable="false" title="# played" type="java.lang.Object"/>
               </Table>
             </Property>
             <Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
@@ -113,16 +108,6 @@
                   <Editor/>
                   <Renderer/>
                 </Column>
-                <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
-                  <Title/>
-                  <Editor/>
-                  <Renderer/>
-                </Column>
-                <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
-                  <Title/>
-                  <Editor/>
-                  <Renderer/>
-                </Column>
               </TableColumnModel>
             </Property>
             <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">

+ 110 - 53
iZplPlugins/JukeBox/src/main/java/de/nplusc/izc/izpl/plugins/jukebox/JukeBox.java

@@ -5,12 +5,10 @@
  */
 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.PlayListEditAPI;
-import de.nplusc.izc.iZpl.API.PlaybackPlugin;
 import de.nplusc.izc.iZpl.API.UIPlugin;
 import de.nplusc.izc.iZpl.API.shared.InvalidPlayListFileException;
-import de.nplusc.izc.iZpl.API.shared.PlayListItem;
 import de.nplusc.izc.tools.baseTools.Detectors;
 import de.nplusc.izc.tools.baseTools.HidableTableColumnModel;
 import java.awt.Dimension;
@@ -39,9 +37,10 @@ import org.apache.logging.log4j.Logger;
  *
  * @author tgoerner
  */
-public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListener
+public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListener,FeaturePlugin,PlaybackStatusUpdater
 {
-    private PlaybackPlugin selectedPlaybackPlugin;
+    
+    private Backend jukeboxBackend;
     private static final Logger l = LogManager.getLogger();
     /**
      * Creates new form JukeBoxGUI
@@ -73,26 +72,25 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
         lblTrackName = new javax.swing.JLabel();
 
         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
-        setPreferredSize(new java.awt.Dimension(480, 800));
 
         tblPLE.setAutoCreateRowSorter(true);
         tblPLE.setModel(new javax.swing.table.DefaultTableModel(
             new Object [][]
             {
-                {null, null, null, null},
-                {null, null, null, null},
-                {null, null, null, null},
-                {null, null, null, null}
+                {null, null},
+                {null, null},
+                {null, null},
+                {null, null}
             },
             new String []
             {
-                "ID", "Title", "# to play", "# played"
+                "ID", "Title"
             }
         )
         {
             boolean[] canEdit = new boolean []
             {
-                false, false, false, false
+                false, false
             };
 
             public boolean isCellEditable(int rowIndex, int columnIndex)
@@ -215,9 +213,9 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
         }
         if((modified&evt.ALT_MASK)!=0)
         {
-            IZPLApi.shutdownWithSave();
+            jukeboxBackend.quitWithSave();
         }
-        selectedPlaybackPlugin.skipTitle();
+        jukeboxBackend.skip();
     }//GEN-LAST:event_btnSkipActionPerformed
 
     private void btnPlayPauseActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnPlayPauseActionPerformed
@@ -232,13 +230,13 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
         int index = (Integer)((DefaultTableModel)tblPLE.getModel()).getValueAt(viewRow,0);
         if(index>=0)
         {
-            PlayListEditAPI.forceElement(index);
+            jukeboxBackend.enqueue(index);
         }
     }//GEN-LAST:event_btnEnqueueActionPerformed
 
     private void btnReloadActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnReloadActionPerformed
     {//GEN-HEADEREND:event_btnReloadActionPerformed
-        PlayListEditAPI.reloadList();
+        jukeboxBackend.reload();
         rebuildTable(false);
     }//GEN-LAST:event_btnReloadActionPerformed
     
@@ -251,9 +249,16 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
     @Override
     public void initializePlugin()
     {
-        l.info("Init UI(JukeBox)");
-        selectedPlaybackPlugin=IZPLApi.getCurrentPlaybackPlugin();
-        l.trace(selectedPlaybackPlugin+"");
+        if(IZPLApi.getUIPlugin()==this)
+        {
+            l.info("Init UI(JukeBox)");
+            jukeboxBackend= new LocalBackend(this);
+        }
+        else
+        {
+            l.info("Loaded as featurePlugin, delaying the init");
+        }
+               
     }
 
     @Override
@@ -262,16 +267,13 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
         /*nothing to do for this plugin*/
     }
     
-    private boolean rebuilding=false;
     private void rebuildTable(boolean recovery)
     {
         try
         {
-            rebuilding = true;
-
             //mdl.setAllColumnsVisible();
-            PlayListEditAPI.refreshKeyList();
-            String[] titles = PlayListEditAPI.getTrackTitles();
+            
+            String[] titles = jukeboxBackend.getTitles();
             for(int i=tblPLE.getRowCount()-1;i>0;i--)
             {
                 ((DefaultTableModel)tblPLE.getModel()).removeRow(i-1);
@@ -280,8 +282,6 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
             {
                 tblPLE.getModel().setValueAt(0,0,0);
                 tblPLE.getModel().setValueAt(titles[0],0,1);
-                tblPLE.getModel().setValueAt(PlayListEditAPI.getTargetPlayCount(0),0,2);
-                tblPLE.getModel().setValueAt(PlayListEditAPI.getPlayCount(0),0,3);
             }
             else
             {
@@ -295,21 +295,17 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
                 ((DefaultTableModel)tblPLE.getModel()).addRow(new Object[]{null,null,null,null});
                 tblPLE.getModel().setValueAt(i,i,0);
                 tblPLE.getModel().setValueAt(titles[i],i,1);
-                tblPLE.getModel().setValueAt(PlayListEditAPI.getTargetPlayCount(i),i,2);
-                tblPLE.getModel().setValueAt(PlayListEditAPI.getPlayCount(i),i,3);
             }
-            rebuilding=false;
         }
         catch(InvalidPlayListFileException e)
         {
-             rebuilding=false;
             if(recovery)
             {
                 l.error("Serious statefile corruption detected");
-                IZPLApi.quickQuitWithoutSaving();
+                IZPLApi.quickQuitWithoutSaving(); //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
-            PlayListEditAPI.reloadList();
+            jukeboxBackend.reload();
             rebuildTable(recovery);
         }
         //mdl.setColumnVisible(0, false);
@@ -334,7 +330,8 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
     {
         if(e.getSource()==seekBar)
         {
-            selectedPlaybackPlugin.seek(seekBar.getValue());
+             
+            jukeboxBackend.seek(seekBar.getValue());
         }
     }
 
@@ -343,7 +340,7 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
     {
         if(e.getSource()==seekBar)
         {
-            selectedPlaybackPlugin.pause();
+            jukeboxBackend.pause();
         }
     }
     @Override
@@ -351,9 +348,11 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
     {
         if(e.getSource()==seekBar)
         {
-            selectedPlaybackPlugin.seek(seekBar.getValue());
+            jukeboxBackend.seek(seekBar.getValue());
             if(playing)
-                selectedPlaybackPlugin.play();
+            {
+                jukeboxBackend.play();
+            }
         }
     }
     
@@ -361,7 +360,7 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
     @Override
     public void setAlbumArt(Image i)
     {
-        
+        //not used for the JukeBox so far
     }
     
     private String trackTime = "--:--";
@@ -429,19 +428,12 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
         //END HACK
         mdl=(HidableTableColumnModel) tblPLE.getColumnModel();
         mdl.setColumnVisible(mdl.getColumn(0), false);
-        //most probably "embedded" device.
-        if(onARM)
-        {
-            //target and current playcount hidden, decluttering
-            mdl.setColumnVisible(mdl.getColumn(1), false);
-            mdl.setColumnVisible(mdl.getColumn(1), false);
-        }
         addWindowListener(new WindowAdapter()
         {
             @Override
             public void windowClosing(WindowEvent e)
             {
-                IZPLApi.shutdownWithSave();
+                jukeboxBackend.quitWithSave();
             }
         });
         seekBar.addMouseListener(this);
@@ -478,19 +470,18 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
     {
         if(!connected)
         {
-            selectedPlaybackPlugin.connectToPlayer();
-            selectedPlaybackPlugin.skipTitle();
+            jukeboxBackend.initBackend();
             connected=true;
         }
         if(playing)
         {
-            selectedPlaybackPlugin.pause();
+            jukeboxBackend.pause();
             btnPlayPause.setText("Play");
             playing=false;
         }
         else
         {
-            selectedPlaybackPlugin.play();
+            jukeboxBackend.play();
             btnPlayPause.setText("Pause");
             playing=true;
         }
@@ -510,10 +501,10 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
     public void refreshScheduledItemList()
     {
         EventQueue.invokeLater(()->{
-        DefaultListModel<String> model = (DefaultListModel<String>) lstScheduled.getModel();
-        model.clear();
-        List<PlayListItem> items = PlayListEditAPI.getScheduledList();
-        items.forEach((e)->{model.addElement(PlayListEditAPI.getTitle(e));});
+            DefaultListModel<String> model = (DefaultListModel<String>) lstScheduled.getModel();
+            model.clear();
+            List<String> items = jukeboxBackend.getScheduledTracks();
+            items.forEach((e)->{model.addElement(e);});
         });
     }
 
@@ -522,6 +513,72 @@ public class JukeBox extends javax.swing.JFrame implements UIPlugin,MouseListene
     {
         EventQueue.invokeLater(()->this.rebuildTable(false));
     }
+
+    @Override
+    public void parseParameter(String param)
+    {
+        if(param!=null&&!param.equals(""))
+        {
+            
+        }
+        else
+        {
+            
+        }
+    }
+
+    @Override
+    public boolean hasUserInterface()
+    {
+        return true;
+    }
+
+    @Override
+    public void openUserInterface()
+    {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public boolean requiresLoadedPlayList()
+    {
+        return false; //not needed since it connects via Network to the Real jukebox
+    }
+
+    
+    
+    
+    
+    //compat stub for the backend
+    @Override
+    public void updateTrackLength(int length)
+    {
+        setTrackLength(length);
+    }
+
+    @Override
+    public void updateTrackTitle(String title)
+    {
+        setTrackName(title);
+    }
+
+    @Override
+    public void updateCurrentPlaybackPosition(int position)
+    {
+        setPlaybackPositionInSeconds(position);
+    }
+
+    @Override
+    public void triggerTableRefresh()
+    {
+        EventQueue.invokeLater(()->rebuildTable(false));
+    }
+
+    @Override
+    public void triggerScheduleRefresh()
+    {
+        refreshScheduledItemList();
+    }
     
     
 }

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

@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2018 iZc
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package de.nplusc.izc.izpl.plugins.jukebox;
+
+import de.nplusc.izc.iZpl.API.IZPLApi;
+import de.nplusc.izc.iZpl.API.PlayListEditAPI;
+import de.nplusc.izc.iZpl.API.PlaybackPlugin;
+import de.nplusc.izc.iZpl.API.shared.InvalidPlayListFileException;
+import de.nplusc.izc.iZpl.API.shared.PlayListItem;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ *
+ * @author iZc <nplusc.de>
+ */
+public class LocalBackend implements Backend
+{
+    private PlaybackPlugin selectedPlaybackPlugin;
+    private static final Logger l = LogManager.getLogger();
+    private PlaybackStatusUpdater u;
+    public LocalBackend(PlaybackStatusUpdater frontend)
+    {
+        u=frontend;
+        selectedPlaybackPlugin=IZPLApi.getCurrentPlaybackPlugin();
+        l.trace(selectedPlaybackPlugin+"");
+    }
+    
+    @Override
+    public void skip()
+    {
+        selectedPlaybackPlugin.skipTitle();
+    }
+
+    @Override
+    public void enqueue(int index)
+    {
+        PlayListEditAPI.forceElement(index);
+    }
+
+    @Override
+    public void reload()
+    {
+        PlayListEditAPI.reloadList();
+    }
+
+    @Override
+    public String[] getTitles() throws InvalidPlayListFileException
+    {
+        PlayListEditAPI.refreshKeyList();
+        return PlayListEditAPI.getTrackTitles();
+    }
+
+    @Override
+    public void quitWithSave()
+    {
+        IZPLApi.shutdownWithSave();
+    }
+
+    @Override
+    public void play()
+    {
+        selectedPlaybackPlugin.play();
+    }
+
+    @Override
+    public void pause()
+    {
+        selectedPlaybackPlugin.pause();
+    }
+
+    @Override
+    public void seek(int pos)
+    {
+        selectedPlaybackPlugin.seek(pos);
+    }
+
+    @Override
+    public void initBackend()
+    {
+        selectedPlaybackPlugin.connectToPlayer();
+        selectedPlaybackPlugin.skipTitle();
+    }
+
+    @Override
+    public List<String> getScheduledTracks()
+    {
+        List<String> results = new LinkedList<>();
+        List<PlayListItem> items = PlayListEditAPI.getScheduledList();
+        items.forEach((e)->{results.add(PlayListEditAPI.getTitle(e));});
+        return results;
+    }
+    
+}

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

@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2018 iZc
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package de.nplusc.izc.izpl.plugins.jukebox;
+
+/**
+ *
+ * @author iZc <nplusc.de>
+ */
+public interface PlaybackStatusUpdater
+{
+    void updateTrackLength(int length);
+    void updateTrackTitle(String title);
+    void updateCurrentPlaybackPosition(int position);
+    void triggerTableRefresh();
+    void triggerScheduleRefresh();
+}

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

@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2018 iZc
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package de.nplusc.izc.izpl.plugins.jukebox;
+
+/**
+ *
+ * @author iZc <nplusc.de>
+ */
+public class RemoteBackend
+{
+    
+}