]> git.sesse.net Git - vlc/blobdiff - bindings/java/VLCExample.java
java bindings huge update
[vlc] / bindings / java / VLCExample.java
index da85cec2406eade83b40d539804e146db379d8c2..29759fad1cdb2ba84448b87a8bf2ce98c09352d1 100644 (file)
@@ -1,7 +1,10 @@
-import org.videolan.jvlc.AudioIntf;
 import org.videolan.jvlc.JVLC;
+import org.videolan.jvlc.MediaDescriptor;
+import org.videolan.jvlc.MediaInstance;
+import org.videolan.jvlc.Playlist;
 import org.videolan.jvlc.VLCException;
-import org.videolan.jvlc.VolumeListener;
+import org.videolan.jvlc.Video;
+import org.videolan.jvlc.event.MediaInstanceListener;
 
 
 public class VLCExample
@@ -24,131 +27,147 @@ public class VLCExample
             }
         }
         JVLC jvlc = new JVLC(args);
+        Playlist playlist = new Playlist(jvlc);
         System.out.println("... done.");
-
-        try
-        {
-            // jvlc.playlist.add("file://" + System.getProperty( "user.dir" ) + "/a.avi", "a.avi");
-            jvlc.playlist.add("file:///home/little/a.avi", "a.avi");
-            // jvlc.playlist.add("file://" + System.getProperty( "user.dir" ) + "/a.mp3", "a.mp3");
-            jvlc.playlist.play(-1, null);
-        }
-        catch (VLCException e)
-        {
-            e.printStackTrace();
-        }
-
-        while (! jvlc.isInputPlaying())
-        {
-            Thread.sleep(100);
-        }
-        while (! jvlc.hasVout() )
-        {
-            Thread.sleep(100);
-        }
-
-        // testing vout functionalities
-        Thread.sleep(2500);
-        if (jvlc.hasVout())
-        {
-            videoInput = true;
-        }
         
-        if (videoInput)
+        MediaDescriptor mediaDescriptor = new MediaDescriptor(jvlc, "/home/carone/a.avi");
+        MediaInstance mediaInstance = mediaDescriptor.getMediaInstance();
+
+        mediaInstance.addListener(new MediaInstanceListener()
         {
-            try
+            @Override
+            public void endReached(MediaInstance mediaInstance)
             {
-                System.out.print(jvlc.video.getWidth());
-                System.out.print("x");
-                System.out.println(jvlc.video.getHeight());
+                System.out.println("Media instance end reached. MRL: " + mediaInstance.getMediaDescriptor().getMrl());
             }
-            catch (VLCException e)
+
+            @Override
+            public void paused(MediaInstance mediaInstance)
             {
-                e.printStackTrace();
+                System.out.println("Media instance paused. MRL: " + mediaInstance.getMediaDescriptor().getMrl());
             }
-        }
-        try
-        {
-            if (videoInput)
-            {
-                System.out.print("Fullscreen... ");
-                jvlc.video.setFullscreen(true);
-                Thread.sleep(3000);
-                System.out.println("real size.");
-                jvlc.video.setFullscreen(false);
-                System.out.print("Taking snapshot... ");
-                jvlc.video.getSnapshot(System.getProperty("user.dir") + "/snap.png");
-                System.out.println("taken. (see " + System.getProperty("user.dir") + "/snap.png )");
-                Thread.sleep(2000);
-                System.out.println("Resizing to 300x300");
-                jvlc.video.setSize(300, 300);
 
-            }
-            jvlc.audio.addVolumeListener(new VolumeListener()
+            @Override
+            public void played(MediaInstance mediaInstance)
             {
-                               public void volumeChanged() {
-                                       System.out.println("====> From the listener: volume changed");
-                               }
-            });
-
-            System.out.print("Muting...");
-            jvlc.audio.setMute(true);
-            Thread.sleep(3000);
-            System.out.println("unmuting.");
-            jvlc.audio.setMute(false);
-            Thread.sleep(3000);
-            System.out.println("Volume is: " + jvlc.audio.getVolume());
-            System.out.print("Setting volume to 150... ");
-            jvlc.audio.setVolume(150);
-            System.out.println("done");
-            System.out.println("== AUDIO INFO ==");
-            int currentChannel = jvlc.audio.getChannel();
-            System.out.println("Audio track number: " + jvlc.audio.getTrack());
-            System.out.println("Audio channel info: " + jvlc.audio.getChannel());
-            System.out.print("Setting left channel... ");
-            jvlc.audio.setChannel(AudioIntf.LEFT_CHANNEL);
-            System.out.println("done.");
-            Thread.sleep(3000);
-            System.out.print("Setting right channel... ");
-            jvlc.audio.setChannel(AudioIntf.RIGHT_CHANNEL);
-            System.out.println("done.");
-            Thread.sleep(3000);
-            System.out.print("Reverting to original channel");
-            jvlc.audio.setChannel(currentChannel);
-            System.out.println("done.");
-            Thread.sleep(3000);
-            System.out.println("INPUT INFORMATION");
-            System.out.println("-----------------");
-            System.out.println("Total length   (ms) :\t" + jvlc.input.getLength());
-            System.out.println("Input time     (ms) :\t" + jvlc.input.getTime());
-            System.out.println("Input position [0-1]:\t" + jvlc.input.getPosition());
-            if (videoInput)
-                System.out.println("Input FPS          :\t" + jvlc.input.getFPS());
+                System.out.println("Media instance played. MRL: " + mediaInstance.getMediaDescriptor().getMrl());
+            }
 
-        }
+            @Override
+            public void positionChanged(MediaInstance mediaInstance)
+            {
+                // TODO Auto-generated method stub
+            }
 
-        catch (Exception e)
-        {
-            System.out.println("Something was wrong. I die :(.");
-            jvlc.destroy();
-            e.printStackTrace();
-            System.exit(0);
-        }
+            @Override
+            public void timeChanged(MediaInstance mediaInstance, long newTime)
+            {
+                System.out.println("new time: " + newTime);
+            }
+        });
+        mediaInstance.play();
+        
+        // MediaInstance mediaInstance = playlist.getMediaInstance();
+        //        
+        // while (! mediaInstance. playlist.isPlaying())
+        // {
+        // Thread.sleep(100);
+        // }
+        // while (! jvlc.hasVout() )
+        // {
+        // Thread.sleep(100);
+        // }
 
-        System.out.println("Everything fine ;)");
-        System.out.println("Playing next item");
+        // testing vout functionalities
+        // Thread.sleep(2500);
+        // if (jvlc.hasVout())
+        // {
+        // videoInput = true;
+        // }
+        //        
+        // if (videoInput)
+        // {
         try
         {
-            jvlc.playlist.next();
+            Video video = new Video(jvlc);
+            System.out.print(video.getWidth(mediaInstance));
+            System.out.print("x");
+            System.out.println(video.getHeight(mediaInstance));
+            System.out.print("Fullscreen... ");
+            video.setFullscreen(mediaInstance, true);
+            Thread.sleep(3000);
+            System.out.println("real size.");
+            video.setFullscreen(mediaInstance, false);
+            System.out.print("Taking snapshot... ");
+            video.getSnapshot(mediaInstance, System.getProperty("user.dir") + "/snap.png", 0, 0);
+            System.out.println("taken. (see " + System.getProperty("user.dir") + "/snap.png )");
+            Thread.sleep(2000);
+            System.out.println("Resizing to 300x300");
+            video.setSize(300, 300);
         }
         catch (VLCException e)
         {
             e.printStackTrace();
         }
 
-        Thread.sleep(3000);
+        // System.out.print("Muting...");
+        // jvlc.audio.setMute(true);
+        // Thread.sleep(3000);
+        // System.out.println("unmuting.");
+        // jvlc.audio.setMute(false);
+        // Thread.sleep(3000);
+        // System.out.println("Volume is: " + jvlc.audio.getVolume());
+        // System.out.print("Setting volume to 150... ");
+        // jvlc.audio.setVolume(150);
+        // System.out.println("done");
+        // System.out.println("== AUDIO INFO ==");
+        // int currentChannel = jvlc.audio.getChannel();
+        // System.out.println("Audio track number: " + jvlc.audio.getTrack());
+        // System.out.println("Audio channel info: " + jvlc.audio.getChannel());
+        // System.out.print("Setting left channel... ");
+        // jvlc.audio.setChannel(AudioIntf.LEFT_CHANNEL);
+        // System.out.println("done.");
+        // Thread.sleep(3000);
+        // System.out.print("Setting right channel... ");
+        // jvlc.audio.setChannel(AudioIntf.RIGHT_CHANNEL);
+        // System.out.println("done.");
+        // Thread.sleep(3000);
+        // System.out.print("Reverting to original channel");
+        // jvlc.audio.setChannel(currentChannel);
+        // System.out.println("done.");
+        // Thread.sleep(3000);
+        // System.out.println("INPUT INFORMATION");
+        // System.out.println("-----------------");
+        // System.out.println("Total length (ms) :\t" + jvlc.input.getLength());
+        // System.out.println("Input time (ms) :\t" + jvlc.input.getTime());
+        // System.out.println("Input position [0-1]:\t" + jvlc.input.getPosition());
+        // if (videoInput)
+        // System.out.println("Input FPS :\t" + jvlc.input.getFPS());
+        //
+        // }
+        //
+        // catch (Exception e)
+        // {
+        // System.out.println("Something was wrong. I die :(.");
+        // jvlc.destroy();
+        // e.printStackTrace();
+        // System.exit(0);
+        // }
+
+        System.out.println("Everything fine ;)");
+        System.out.println("Playing next item");
+        // try
+        // {
+        // jvlc.playlist.next();
+        // }
+        // catch (VLCException e)
+        // {
+        // e.printStackTrace();
+        // }
+        //
+        // Thread.sleep(3000);
 
-        jvlc.destroy();
+        // jvlc.destroy();
         return;
     }
 }