Browse Source

More Prepares for iZpl 2.0

git-svn-id: http://repo.nplusc.de/svn/iZink@179 8b19561d-0d00-6744-8ac1-9afc8f58a8aa
masterX244 11 years ago
parent
commit
0ec60fb274

+ 20 - 0
iZpl/src/de/nplusc/izc/iZpl/IZplGUI.java

@@ -0,0 +1,20 @@
+package de.nplusc.izc.iZpl;
+
+import javax.swing.JFrame;
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author LH
+ */
+public class IZplGUI extends JFrame
+{
+    public IZplGUI()
+    {
+        //vlc -Irc --extraintf=cad --rc-host 127.0.0.1:9264 
+    }
+}

+ 79 - 0
iZpl/src/de/nplusc/izc/iZpl/MultiPlayListItem.java

@@ -0,0 +1,79 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package de.nplusc.izc.iZpl;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ *
+ * @author LH
+ */
+public class MultiPlayListItem implements PlayListItem
+{
+    private List<String> path,Title;
+    private int playcount,countPlayed;
+
+    public MultiPlayListItem(String[] path, String[] Title, int playcount)
+    {
+        this.path = Arrays.asList(path);
+        this.Title = Arrays.asList(path);
+        this.playcount = playcount;
+        countPlayed=0; //noch nie gespielt als default; bei reload wird anderweitig verglichen :P
+    }
+
+    public String getPath(int i)
+    {
+        return path.get(i);
+    }
+
+    public void setPath(String path, int i)
+    {
+        this.path.remove(i);
+        this.path.add(i, path);
+    }
+
+    public String getTitle(int i)
+    {
+        return Title.get(i);
+    }
+
+    public void setTitle(String Title, int i)
+    {
+        this.Title.remove(i);
+        this.Title.add(i,Title);
+    }
+
+    public int getPlaycount()
+    {
+        return playcount;
+    }
+
+    public void setPlaycount(int playcount)
+    {
+        this.playcount = playcount;
+    }
+
+    public int getCountPlayed()
+    {
+        return countPlayed;
+    }
+
+    public void setCountPlayed(int countPlayed)
+    {
+        this.countPlayed = countPlayed;
+    }
+    
+    public String getM3UElement()
+    {
+        String ret = "";
+        for (int i = 0; i < path.size(); i++)
+        {
+            ret+=path.get(i)+"\n"+Title.get(i)+"\n";
+            
+        }
+        return ret.trim();
+    }
+}

+ 13 - 0
iZpl/src/de/nplusc/izc/iZpl/PLReader.java

@@ -268,4 +268,17 @@ public class PLReader
         return mergedLists;
         return mergedLists;
     }
     }
     
     
+    
+    
+    public static HashMap<String,PlayListItem> readListAlternative(String path, int rd,int prioritybase)
+    {
+        String[] playListRaw = FileTK.fileload(path);//temporär ne bestimmte hardcoden
+        
+        
+        
+        
+        return null;
+    }
+    
+    
 }
 }

+ 18 - 0
iZpl/src/de/nplusc/izc/iZpl/PlayListItem.java

@@ -0,0 +1,18 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package de.nplusc.izc.iZpl;
+
+/**
+ *
+ * @author LH
+ */
+public interface PlayListItem
+{
+    public String getM3UElement();// erzeugt den M3U-Code zum aujsgeben an den VauEllCeh-er
+    public int getPlaycount(); 
+    public void setPlaycount(int playcount);
+    public int getCountPlayed();
+    public void setCountPlayed(int countPlayed);
+}

+ 69 - 0
iZpl/src/de/nplusc/izc/iZpl/SinglePlayListItem.java

@@ -0,0 +1,69 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package de.nplusc.izc.iZpl;
+
+/**
+ *
+ * @author LH
+ */
+public class SinglePlayListItem implements PlayListItem
+{
+    private String path,Title;
+    private int playcount,countPlayed;
+
+    public SinglePlayListItem(String path, String Title, int playcount)
+    {
+        this.path = path;
+        this.Title = Title;
+        this.playcount = playcount;
+        countPlayed=0; //noch nie gespielt als default; bei reload wird anderweitig verglichen :P
+    }
+
+    public String getPath()
+    {
+        return path;
+    }
+
+    public void setPath(String path)
+    {
+        this.path = path;
+    }
+
+    public String getTitle()
+    {
+        return Title;
+    }
+
+    public void setTitle(String Title)
+    {
+        this.Title = Title;
+    }
+
+    public int getPlaycount()
+    {
+        return playcount;
+    }
+
+    public void setPlaycount(int playcount)
+    {
+        this.playcount = playcount;
+    }
+
+    public int getCountPlayed()
+    {
+        return countPlayed;
+    }
+
+    public void setCountPlayed(int countPlayed)
+    {
+        this.countPlayed = countPlayed;
+    }
+    
+    public String getM3UElement()
+    {
+        return path+"\n"+Title;
+    }
+    
+}

+ 216 - 0
iZpl/src/de/nplusc/izc/iZpl/VlcRC.java

@@ -0,0 +1,216 @@
+package de.nplusc.izc.iZpl;
+
+import java.beans.PropertyChangeSupport;
+import java.io.*;
+import java.io.IOException;
+import java.nio.CharBuffer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.commons.net.telnet.*;
+import org.apache.commons.net.telnet.TelnetClient;
+
+/**
+ *  Exposes control of VLC media player (videolan.org) from java. VLC must be set up to open a telnet control on localhost:4444.
+ * <p>
+ * For VLC 1.1.5, use the following setup to expose the remote control (rc) interrface for telnet control:
+ * <p>
+ * This setting is in VLC Tools/Preferences/Show settings (All)/Interface/Main interfaces. Select the "Remote Control Interface" and replace "oldrc" with "rc" in the text field.
+ * In VLC Tools/Preferences/Show settings (All)/Interface/Main interfaces/RC/TCP command input, put the string "localhost:4444" in the text field.
+ *
+ * @author Tobi
+ */
+public class VlcRC extends TelnetClient implements Runnable, TelnetNotificationHandler {
+
+    /** VLC should be started with as "vlc --rc-host=localhost:4444" */
+    public static final int VLC_PORT = 4444;
+    static final Logger log = Logger.getLogger("VLCControl");
+    private CharBuffer cbuf = CharBuffer.allocate(1024);
+    private static VlcRC staticInstance = null; // used to communicate among instances the active client
+    private PropertyChangeSupport support=new PropertyChangeSupport(this);  // listeners get informed by output from VLC strings
+
+    public VlcRC() {
+    }
+
+    @Override
+    public void disconnect() throws IOException {
+        sendCommand("quit");
+        super.disconnect();
+    }
+
+    public void connect() throws IOException {
+        staticInstance = this; // used by reader to get input stream
+        try {
+            staticInstance.connect("localhost", VLC_PORT);
+            Thread thread = new Thread(new VlcRC()); // starts the thread to get the text sent back from VLC
+            thread.start();
+            staticInstance.registerNotifHandler(this); // notifications call back to logger
+            Runtime.getRuntime().addShutdownHook(new Thread() { // shutdown hook here makes sure to disconnect cleanly, as long as we are not terminated
+
+                @Override
+                public void run() {
+                    try {
+                        if (isConnected()) {
+                            disconnect();
+                        }
+                    } catch (IOException ex) {
+                        log.warning(ex.toString());
+                    }
+                }
+            });
+        } catch (IOException e) {
+            log.warning("couldn't connect to VLC - you may need to start VLC with command line \"vlc --rc-host=localhost:4444\"");
+            throw new IOException(e);
+        }
+    }
+
+ 
+
+    /** Sends a string command.  Commands do not need to be terminated with a newline.
+    <p>
+    <pre>
+    +----[ Remote control commands ]
+    | add XYZ  . . . . . . . . . . . . . . . . . . . . add XYZ to playlist
+    | enqueue XYZ  . . . . . . . . . . . . . . . . . queue XYZ to playlist
+    | playlist . . . . . . . . . . . . . .show items currently in playlist
+    | search [string]  . .  search for items in playlist (or reset search)
+    | sort key . . . . . . . . . . . . . . . . . . . . . sort the playlist
+    | sd [sd]  . . . . . . . . . . . . . show services discovery or toggle
+    | play . . . . . . . . . . . . . . . . . . . . . . . . . . play stream
+    | stop . . . . . . . . . . . . . . . . . . . . . . . . . . stop stream
+    | next . . . . . . . . . . . . . . . . . . . . . .  next playlist item
+    | prev . . . . . . . . . . . . . . . . . . . .  previous playlist item
+    | goto . . . . . . . . . . . . . . . . . . . . . .  goto item at index
+    | repeat [on|off]  . . . . . . . . . . . . . .  toggle playlist repeat
+    | loop [on|off]  . . . . . . . . . . . . . . . .  toggle playlist loop
+    | random [on|off]  . . . . . . . . . . . . . .  toggle playlist random
+    | clear  . . . . . . . . . . . . . . . . . . . . . .clear the playlist
+    | status . . . . . . . . . . . . . . . . . . . current playlist status
+    | title [X]  . . . . . . . . . . . . . . set/get title in current item
+    | title_n  . . . . . . . . . . . . . . . .  next title in current item
+    | title_p  . . . . . . . . . . . . . .  previous title in current item
+    | chapter [X]  . . . . . . . . . . . . set/get chapter in current item
+    | chapter_n  . . . . . . . . . . . . . .  next chapter in current item
+    | chapter_p  . . . . . . . . . . . .  previous chapter in current item
+    |
+    | seek X . . . . . . . . . . . seek in seconds, for instance `seek 12'
+    | pause  . . . . . . . . . . . . . . . . . . . . . . . .  toggle pause
+    | fastforward  . . . . . . . . . . . . . . . . . . set to maximum rate
+    | rewind . . . . . . . . . . . . . . . . . . . . . set to minimum rate
+    | faster . . . . . . . . . . . . . . . . . .  faster playing of stream
+    | slower . . . . . . . . . . . . . . . . . .  slower playing of stream
+    | normal . . . . . . . . . . . . . . . . . .  normal playing of stream
+    | rate [playback rate] . . . . . . . . . .  set playback rate to value
+    | frame  . . . . . . . . . . . . . . . . . . . . . play frame by frame
+    | fullscreen, f, F [on|off]  . . . . . . . . . . . . toggle fullscreen
+    | info . . . . . . . . . . . . . .information about the current stream
+    | stats  . . . . . . . . . . . . . . . .  show statistical information
+    | get_time . . . . . . . . . .seconds elapsed since stream's beginning
+    | is_playing . . . . . . . . . . . .  1 if a stream plays, 0 otherwise
+    | get_title  . . . . . . . . . . . . . the title of the current stream
+    | get_length . . . . . . . . . . . .  the length of the current stream
+    |
+    | volume [X] . . . . . . . . . . . . . . . . . .  set/get audio volume
+    | volup [X]  . . . . . . . . . . . . . . . .raise audio volume X steps
+    | voldown [X]  . . . . . . . . . . . . . .  lower audio volume X steps
+    | adev [X] . . . . . . . . . . . . . . . . . . . .set/get audio device
+    | achan [X]  . . . . . . . . . . . . . . . . . .set/get audio channels
+    | atrack [X] . . . . . . . . . . . . . . . . . . . set/get audio track
+    | vtrack [X] . . . . . . . . . . . . . . . . . . . set/get video track
+    | vratio [X] . . . . . . . . . . . . . . . .set/get video aspect ratio
+    | vcrop, crop [X]  . . . . . . . . . . . . . . . .  set/get video crop
+    | vzoom, zoom [X]  . . . . . . . . . . . . . . . .  set/get video zoom
+    | snapshot . . . . . . . . . . . . . . . . . . . . take video snapshot
+    | strack [X] . . . . . . . . . . . . . . . . . set/get subtitles track
+    | hotkey, key [hotkey name]  . . . . . . . . . . simulate hotkey press
+    | menu [on|off|up|down|left|right|select]  . . . . . . . . . .use menu
+    |
+    | set [var [value]]  . . . . . . . . . . . . . . . . . set/get env var
+    | save_env . . . . . . . . . . . .  save env vars (for future clients)
+    | alias [cmd]  . . . . . . . . . . . . . . . . set/get command aliases
+    | description  . . . . . . . . . . . . . . . . . .describe this module
+    | license  . . . . . . . . . . . . . . . . print VLC's license message
+    | help, ? [pattern]  . . . . . . . . . . . . . . . . . .a help message
+    | longhelp [pattern] . . . . . . . . . . . . . . a longer help message
+    | logout . . . . . . . . . . . . . .  exit (if in a socket connection)
+    | quit . . . . . . . .  quit VLC (or logout if in a socket connection)
+    | shutdown . . . . . . . . . . . . . . . . . . . . . . . .shutdown VLC
+    +----[ end of help ]
+    </pre>
+
+     */
+    public String sendCommand(String s) throws IOException {
+        if (!isConnected()) {
+            connect();
+        }
+        if (s == null) {
+            return null;
+        }
+        if (!s.endsWith("\n")) {
+            s = s + "\n";
+        }
+        getOutputStream().write(s.getBytes());
+        getOutputStream().flush();
+        return s;
+    }
+
+    public static String PAUSE="pause", PLAY="play", STOP="stop", NEXT="next", PREV="prev", VOLUP="volup 1", VOLDOWN = "voldown 1";
+    public static final String CLIENT_MESSAGE="ClientMessage";
+    /***
+     * Reader thread.
+     * Reads lines from the TelnetClient and echoes them
+     * on the logger.
+     * PropertyChangeListeners are called with CLIENT_MESSAGE and String sent from VLC.
+     ***/
+    @Override
+    public void run() {
+        InputStream instr = staticInstance.getInputStream();
+
+        byte[] buff = new byte[1024];
+        int ret_read = 0;
+
+        try {
+            do {
+                ret_read = instr.read(buff);
+                if (ret_read > 0) {
+                    String s=new String(buff, 0, ret_read);
+                    log.info(s);
+                    staticInstance.getSupport().firePropertyChange(CLIENT_MESSAGE, null, s); // listener on static instance that actually is connected gets the message
+                }
+            } while (ret_read >= 0);
+        } catch (Exception e) {
+            log.log(Level.WARNING, "Reader ending - Exception while reading socket:{0}", e.getMessage());
+        }
+    }
+
+       /***
+     * Callback method called when TelnetClient receives an option
+     * negotiation command.
+     * <p>
+     * @param negotiation_code - type of negotiation command received
+     * (RECEIVED_DO, RECEIVED_DONT, RECEIVED_WILL, RECEIVED_WONT)
+     * <p>
+     * @param option_code - code of the option negotiated
+     * <p>
+     ***/
+    @Override
+    public void receivedNegotiation(int negotiation_code, int option_code) {
+        String command = null;
+        if (negotiation_code == TelnetNotificationHandler.RECEIVED_DO) {
+            command = "DO";
+        } else if (negotiation_code == TelnetNotificationHandler.RECEIVED_DONT) {
+            command = "DONT";
+        } else if (negotiation_code == TelnetNotificationHandler.RECEIVED_WILL) {
+            command = "WILL";
+        } else if (negotiation_code == TelnetNotificationHandler.RECEIVED_WONT) {
+            command = "WONT";
+        }
+        log.log(Level.INFO, "Received {0} for option code {1}", new Object[]{command, option_code});
+    }
+
+    /**
+     * @return the support. Listeners can get the stuff sent back from VLC with CLIENT_MESSAGE events.
+     */
+    public PropertyChangeSupport getSupport() {
+        return support;
+    }
+}