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

play/pause working on visualized player

git-svn-id: http://repo.nplusc.de/svn/iZink@304 8b19561d-0d00-6744-8ac1-9afc8f58a8aa
masterX244 10 роки тому
батько
коміт
1f9db90d5c

+ 5 - 13
iZStreamer/src/de/nplusc/izc/izstreamer/Player.java

@@ -26,11 +26,13 @@ public class Player extends javax.swing.JFrame implements PlayerStructure
 
     /**
      * Creates new form Player
+     * @param g refers to controller
      */
     public Player(StreamGUI g)
     {
         playmanager=g;
         initComponents();
+        setResizable(false);
     }
     //public static final String StreamTitle = "";
     private StreamGUI playmanager;
@@ -252,22 +254,12 @@ public class Player extends javax.swing.JFrame implements PlayerStructure
             public void run()
             {
                 VisualizedGUI vgui = new VisualizedGUI();
-                vgui.setSize(iZstreamer.width, iZstreamer.height);
+                //vgui.setSize(iZstreamer.width, iZstreamer.height);
                 vgui.validate();
                 vgui.setVisible(true);
-                new Thread(()->{
-                try
-                {
-                    Thread.sleep(500);
-                    StreamGUI.player.play();
-                }
-                catch (InterruptedException ex)
-                {
-                    ex.printStackTrace();
-                    
-                }}).start();
+                //StreamGUI.player.play();
                 //StreamGUI.player.setPlayerStructure(vgui);
-                
+
             }
         });
     }

+ 33 - 5
iZStreamer/src/de/nplusc/izc/izstreamer/StreamGUI.java

@@ -7,9 +7,12 @@ package de.nplusc.izc.izstreamer;
 
 import java.awt.Canvas;
 import java.io.File;
+import javax.swing.JFrame;
 import uk.co.caprica.vlcj.player.MediaPlayer;
 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.player.embedded.videosurface.VideoSurface;
 
 /**
  *
@@ -21,7 +24,7 @@ public class StreamGUI
 
     private final int height = iZstreamer.height;
     boolean stopPlay = false;
-    public MediaPlayer m;
+    public MediaPlayer m=null;
     private boolean fs=true;
     private String url = "http://31.7.177.108:2294";//"D:\\mp3\\assorted Earworms\\22 - StarDisc - Fernando Pepe.flac";//
     public static StreamGUI player = new StreamGUI();
@@ -30,7 +33,9 @@ public class StreamGUI
     {
         thix=x;
     }
-    Canvas lc = null;
+    VisualizedGUIOverlay vgui;
+    private CanvasVideoSurface v;
+    private Canvas lc = null;
     public void play()
     {
         //if(m==null)
@@ -39,15 +44,27 @@ public class StreamGUI
             String vpath = new File(Player.class.getProtectionDomain().
                                 getCodeSource().getLocation().getPath()).getParent()+"\\vis\\";
             System.out.println(vpath);
-            MediaPlayerFactory mpf = new MediaPlayerFactory("--projectm-preset-path="+vpath,"--audio-visual=projectM");
-            m = mpf.newEmbeddedMediaPlayer();
+            
+            
             
            Canvas s = thix.getBackGround();
             if(s!=null&&s!=lc)
             {
-                 ((EmbeddedMediaPlayer)m).setVideoSurface(mpf.newVideoSurface(s));
+                 MediaPlayerFactory mpf = new MediaPlayerFactory("--projectm-preset-path="+vpath,"--audio-visual=projectM");
+                  m = mpf.newEmbeddedMediaPlayer();
+                  v=mpf.newVideoSurface(s);
+                 ((EmbeddedMediaPlayer)m).setVideoSurface(v);
+                 //vgui=new VisualizedGUIOverlay(this,(JFrame)thix);
+                 //((EmbeddedMediaPlayer)m).setOverlay(vgui);
+                 //((EmbeddedMediaPlayer)m).enableOverlay(true);
+            }
+            else
+            {
+                MediaPlayerFactory mpf = new MediaPlayerFactory();
+                m = mpf.newHeadlessMediaPlayer();
             }
             m.startMedia(url);
+            
             fs=true;
             lc=s;
         }
@@ -55,13 +72,24 @@ public class StreamGUI
         {
             m.play();
         }
+        new Thread(()->{
         while(!stopPlay)
         {
             String tit = m.getMediaMeta().getTitle();
             thix.setPlaying(tit);
+            try
+            {
+                Thread.sleep(50);
+            }
+            catch (InterruptedException ex)
+            {
+                ex.printStackTrace();
+            }
         }
         m.pause();
         stopPlay=false;//ARSCHFOTZE!
+        }).start();
+        
         
     }
     

+ 70 - 6
iZStreamer/src/de/nplusc/izc/izstreamer/VisualizedGUI.java

@@ -6,12 +6,21 @@
 
 package de.nplusc.izc.izstreamer;
 
+import de.nplusc.izc.tools.baseTools.Messagers;
 import java.awt.Canvas;
+import java.awt.Desktop;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
+import java.awt.event.ActionEvent;
 import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import javax.swing.JButton;
 import javax.swing.JFrame;
+import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JSlider;
 import javax.swing.WindowConstants;
 
 /**
@@ -41,9 +50,9 @@ public class VisualizedGUI extends JFrame implements PlayerStructure
             }*/
 
     @Override
-    public void setPlaying(String tit)
+    public void setPlaying(String titp)
     {
-        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+        tit.setText("Now playing: "+ titp);
     }
 
     @Override
@@ -51,7 +60,10 @@ public class VisualizedGUI extends JFrame implements PlayerStructure
     {
       //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
     }
-    
+    JLabel tit;
+    JButton play,info,last20trax;
+    JSlider vol;
+    private boolean playing;
     public VisualizedGUI()
     {
         /*
@@ -64,13 +76,65 @@ public class VisualizedGUI extends JFrame implements PlayerStructure
         setLayout(new GridLayout(1, 1));
        */
        // this.add(c);
+        setLayout(null);
         surface = new Canvas();
-        surface.setSize(x, y);
-        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+        surface.setBounds(0,0,x, y);
         add(surface);
+        setSize(x,y+90);
+        tit=new JLabel("Now playing:");
+        tit.setBounds(0, y,x, 15);
+        play = new JButton("Play");
+        play.setBounds(0,y+15,150,40);
+        info = new JButton("Play");
+        info.setBounds(160,y+15,50,30);
+        last20trax = new JButton("PLAY");
+        last20trax.setBounds(220,y+15,40,25);
+        add(play);
+        add(tit);
+        add(info);
+        add(last20trax);
+        play.addActionListener((ActionEvent e) ->
+        {
+            if (playing)
+            {
+                play.setText("PLAY");
+                StreamGUI.player.stopPlay=true;
+            }
+            else
+            {
+                play.setText("STOP");
+                StreamGUI.player.play();
+            }
+            playing = !playing;
+            
+        });
+        info.addActionListener((ActionEvent e) ->
+        {
+            Messagers.SingleLineMsg("Not implemented", "Klappe halten.....");
+        });
+        
+         last20trax.addActionListener((ActionEvent e) ->
+        {
+            try
+            {
+                Desktop.getDesktop().browse(new URI("http://31.7.177.108:2294/played.html"));
+            }
+            catch (URISyntaxException ex)
+            {
+                ex.printStackTrace();
+            }
+            catch (IOException ex)
+            {
+                ex.printStackTrace();
+            }
+        });
+        
+        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+        validate();
         StreamGUI.player.setPlayerStructure(this);
+        setResizable(false);
         
-       // setSize(x, y);
+        // setSize(x, y);
     }
 
     @Override

+ 75 - 0
iZStreamer/src/de/nplusc/izc/izstreamer/VisualizedGUIOverlay.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.izstreamer;
+
+import com.sun.awt.AWTUtilities;
+import com.sun.jna.platform.WindowUtils;
+import java.awt.Canvas;
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+
+/**
+ *
+ * @author LH
+ */
+public class VisualizedGUIOverlay extends Window implements PlayerStructure
+{
+    private StreamGUI ctrl;
+    private JButton p ;
+    private static int x = iZstreamer.width;
+    private static int y =iZstreamer.height;
+    private boolean playing=true;//hack...
+        
+    public VisualizedGUIOverlay(StreamGUI s,JFrame owner)
+    {
+        super(owner,WindowUtils.getAlphaCompatibleGraphicsConfiguration());
+        //setDefaultCloseOperation(EXIT_ON_CLOSE);;
+        AWTUtilities.setWindowOpaque(this, false);
+        setSize(x,y);
+        ctrl=s;
+        setLayout(null);
+        p = new JButton("STOP");
+        p.setSize(60, 25);
+        
+        p.setBounds(x-60, y-25, 60, 25);
+        this.add(p);
+        p.addActionListener((ActionEvent e) ->
+        {
+            if (playing)
+            {
+                p.setText("PLAY");
+            }
+            else
+            {
+                p.setText("STOP");
+            }
+            playing = !playing;
+            ctrl.play();
+        });
+    }
+
+    @Override
+    public void setPlaying(String tit)
+    {
+        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public void updateSender(String s)
+    {
+        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public Canvas getBackGround()
+    {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+           
+}

+ 2 - 1
iZStreamer/src/de/nplusc/izc/izstreamer/iZstreamer.java

@@ -51,7 +51,8 @@ public class iZstreamer
                     + "set bindir=%~dp0\n"
                     + "cd %bindir%\n"
                     + "start javaw -jar -Xmx128M %bindir%\\iZStreamer.jar --appsource #sfxjar#\n"
-                    + "REM DUMMYDUMMYDUMMYDUMMY", jpath + File.separator + "params.sfx");//<<<<HACK!
+                    + "REM DUMMYDUMMYDUMMYDUMMY",//<<<<HACK!
+                    jpath + File.separator + "params.sfx");
             new File(jpath + "release.jar").delete();//alte jar ausm weg räumen falls nicht schon geschehen
             String apath = jpath + File.separator + "iZstreamerStandalone.jar";
             IZpackage.wrapArchive(apath, jpath);