Browse Source

prototype of Visualisations-Engine

git-svn-id: http://repo.nplusc.de/svn/iZink@302 8b19561d-0d00-6744-8ac1-9afc8f58a8aa
masterX244 10 years ago
parent
commit
4ad93e42bc

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

@@ -6,10 +6,16 @@
 
 package de.nplusc.izc.izstreamer;
 
+import com.sun.jna.Memory;
+import java.awt.Canvas;
 import java.awt.Desktop;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import javafx.application.Application;
+import javax.swing.JPanel;
+import uk.co.caprica.vlcj.player.direct.BufferFormat;
+import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer;
 
 /**
  *
@@ -21,12 +27,13 @@ public class Player extends javax.swing.JFrame implements PlayerStructure
     /**
      * Creates new form Player
      */
-    public Player()
+    public Player(StreamGUI g)
     {
+        playmanager=g;
         initComponents();
     }
     //public static final String StreamTitle = "";
-    private static final StreamGUI playmanager = new StreamGUI();
+    private StreamGUI playmanager;
     /**
      * This method is called from within the constructor to
      * initialize the form.
@@ -152,7 +159,7 @@ public class Player extends javax.swing.JFrame implements PlayerStructure
             btnPlay.setText("STOP");
             lblSender.setText("Connecting....");
                 new Thread(()->
-                playmanager.play("http://31.7.177.108:2294",this)).start();
+                playmanager.play()).start();
                 //http://31.7.177.108:2299/played.html
             isPlaying=true;
         }
@@ -172,7 +179,7 @@ public class Player extends javax.swing.JFrame implements PlayerStructure
     {//GEN-HEADEREND:event_btnLastPlayedActionPerformed
         try
         {
-            Desktop.getDesktop().browse(new URI("http://31.7.177.108:2299/played.html"));
+            Desktop.getDesktop().browse(new URI("http://31.7.177.108:2294/played.html"));
         }
         catch (URISyntaxException ex)
         {
@@ -188,6 +195,14 @@ public class Player extends javax.swing.JFrame implements PlayerStructure
     {
         lblTIT.setText("Now playing: "+tit);
     }
+
+    @Override
+    public Canvas getBackGround()
+    {
+        return null;
+    }
+    
+    
     
     /**
      * @param args the command line arguments
@@ -236,10 +251,28 @@ public class Player extends javax.swing.JFrame implements PlayerStructure
         {
             public void run()
             {
-                new Player().setVisible(true);
+                VisualizedGUI vgui = new VisualizedGUI();
+                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.setPlayerStructure(vgui);
+                
             }
         });
     }
+    
+    
 
     // Variables declaration - do not modify//GEN-BEGIN:variables
     private javax.swing.JButton Info;
@@ -249,4 +282,5 @@ public class Player extends javax.swing.JFrame implements PlayerStructure
     private javax.swing.JLabel lblTIT;
     private javax.swing.JSlider sliderVolume;
     // End of variables declaration//GEN-END:variables
+
 }

+ 5 - 0
iZStreamer/src/de/nplusc/izc/izstreamer/PlayerStructure.java

@@ -6,6 +6,9 @@
 
 package de.nplusc.izc.izstreamer;
 
+import java.awt.Canvas;
+
+
 /**
  *
  * @author LH
@@ -14,4 +17,6 @@ public interface PlayerStructure
 {
     public void setPlaying(String tit);
     public void updateSender(String s);
+    public Canvas getBackGround();
+            
 }

+ 27 - 3
iZStreamer/src/de/nplusc/izc/izstreamer/StreamGUI.java

@@ -5,8 +5,11 @@
  */
 package de.nplusc.izc.izstreamer;
 
+import java.awt.Canvas;
+import java.io.File;
 import uk.co.caprica.vlcj.player.MediaPlayer;
 import uk.co.caprica.vlcj.player.MediaPlayerFactory;
+import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
 
 /**
  *
@@ -14,16 +17,36 @@ import uk.co.caprica.vlcj.player.MediaPlayerFactory;
  */
 public class StreamGUI
 {
+    private final int width = iZstreamer.width;
 
+    private final int height = iZstreamer.height;
     boolean stopPlay = false;
     public MediaPlayer m;
     private boolean fs=true;
-    public void play(String url, PlayerStructure thix)
+    private String url = "D:\\mp3\\assorted Earworms\\22 - StarDisc - Fernando Pepe.flac";//"http://31.7.177.108:2294";
+    public static StreamGUI player = new StreamGUI();
+    private PlayerStructure thix;
+    public void setPlayerStructure(PlayerStructure x)
+    {
+        thix=x;
+    }
+            
+    public void play()
     {
         //if(m==null)
         if(fs)
         {
-            m = new MediaPlayerFactory().newHeadlessMediaPlayer();
+            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)
+            {
+                 ((EmbeddedMediaPlayer)m).setVideoSurface(mpf.newVideoSurface(s));
+            }
             m.startMedia(url);
             fs=true;
         }
@@ -33,7 +56,8 @@ public class StreamGUI
         }
         while(!stopPlay)
         {
-        thix.setPlaying(m.getMediaMeta().getTitle());
+            String tit = m.getMediaMeta().getTitle();
+            thix.setPlaying(tit);
         }
         m.pause();
         stopPlay=false;//ARSCHFOTZE!

+ 88 - 1
iZStreamer/src/de/nplusc/izc/izstreamer/VisualizedGUI.java

@@ -6,11 +6,98 @@
 
 package de.nplusc.izc.izstreamer;
 
+import java.awt.Canvas;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
 /**
  *
  * @author LH
  */
-public class VisualizedGUI
+
+public class VisualizedGUI extends JFrame implements PlayerStructure
 {
+    private BufferedImage image;
+    private final int x = iZstreamer.width;
+    private final int y = iZstreamer.height;
+    private Canvas surface;
+            
+   // @Override
+           /* public void display(DirectMediaPlayer mediaPlayer, Memory[] nativeBuffer, BufferFormat bufferFormat)
+            {
+                BufferedImage i = surface.getImage();
+                WritableRaster r = i.getRaster();
+                int[] rgbbuffer = ((DataBufferInt) r.getDataBuffer()).getData();
+                //code from VLCJs renderCallbackAdapter class
+                ByteBuffer b = nativeBuffer[0].getByteBuffer(0L, nativeBuffer[0].size());
+                int destBbS = bufferFormat.getHeight() * bufferFormat.getWidth();
+                System.out.println(b.capacity()/4+"|"+destBbS);
+                b.asIntBuffer().get(rgbbuffer, 0, destBbS);
+                repaint();
+            }*/
+
+    @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.
+    }
+    
+    public VisualizedGUI()
+    {
+        /*
+        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+        surface= new EJP();
+        image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().
+                getDefaultConfiguration().createCompatibleImage(x,y);
+        surface.setSize(x, y);
+        surface.setdrawIMG(image);
+        setLayout(new GridLayout(1, 1));
+       */
+       // this.add(c);
+        surface = new Canvas();
+        surface.setSize(x, y);
+        add(surface);
+        StreamGUI.player.setPlayerStructure(this);
+        
+       // setSize(x, y);
+    }
+
+    @Override
+    public Canvas getBackGround()
+    {
+        return surface;
+    }
     
+    
+    
+    private class EJP extends JPanel
+{
+        private BufferedImage image;
+        
+        private BufferedImage getImage()
+        {
+            return image;
+        }
+
+        public void setdrawIMG(BufferedImage image) {
+            this.image = image;
+        }
+
+        @Override
+        public void paint(Graphics g) 
+            {
+            Graphics2D g2 = (Graphics2D)g;
+            g2.drawImage(image, null, 0, 0);
+            // You could draw on top of the image here...
+            }
+        };
 }

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

@@ -28,7 +28,8 @@ import uk.co.caprica.vlcj.runtime.RuntimeUtil;
  */
 public class iZstreamer
 {
-
+    public static final int width=600;
+    public static int height=400;
     public static void main(String[] args)
     {
         if (args.length > 0 && args[0].equals("--mkdist"))