]> git.sesse.net Git - vlc/blob - bindings/java/VLCExample.java
bindings for new audio functions, thanks to Philippe Morin
[vlc] / bindings / java / VLCExample.java
1 import org.videolan.jvlc.JVLC;
2 import org.videolan.jvlc.VLCException;
3
4
5 public class VLCExample 
6 {
7
8     public static void main( String[] args )
9     {
10         boolean videoInput = false;
11         JVLC jvlc = new JVLC(args);
12         try {
13         //jvlc.playlist.add("file://" + System.getProperty( "user.dir" ) + "/a.avi", "a.avi");
14                 jvlc.playlist.add("file:///home/little/a.avi", "a.avi");
15         jvlc.playlist.add("file://" + System.getProperty( "user.dir" ) + "/a.mp3", "a.mp3");
16         jvlc.playlist.play( -1 , null );
17         } catch (VLCException e) {
18                 e.printStackTrace();
19         }
20         while (! jvlc.isInputPlaying()) ;
21         while (! jvlc.hasVout() );        
22         
23         
24         
25         // testing vout functionalities
26
27         try {
28                 Thread.sleep(2500);
29                 if (jvlc.hasVout()) videoInput = true;
30                 } catch (InterruptedException e) {
31                                 e.printStackTrace();
32                 }
33
34         if (videoInput) {
35                 try {
36                         System.out.print(jvlc.video.getWidth());
37                         System.out.print("x");
38                         System.out.println(jvlc.video.getHeight());
39                 } catch (VLCException e) {
40                         e.printStackTrace();
41                 }
42         }
43         try 
44         {
45                 if (videoInput) {
46                         System.out.print("Fullscreen... ");             
47                         jvlc.video.setFullscreen(true);
48                         Thread.sleep(3000);
49                         System.out.println("real size.");
50                 jvlc.video.setFullscreen(false);
51                 System.out.print("Taking snapshot... ");
52                 jvlc.video.getSnapshot( System.getProperty( "user.dir" ) + "/snap.png");
53                 System.out.println("taken. (see " + System.getProperty( "user.dir" ) + "/snap.png )");
54                         Thread.sleep(2000);
55                 System.out.println("Resizing to 300x300");
56                 jvlc.video.setSize(300, 300);
57                                 
58                 }
59             System.out.print("Muting...");
60             jvlc.audio.setMute(true);
61             Thread.sleep(3000);
62             System.out.println("unmuting.");
63             jvlc.audio.setMute(false);
64             Thread.sleep(3000);
65             System.out.println("Volume is: " + jvlc.audio.getVolume());
66             System.out.print("Setting volume to 150... ");
67             jvlc.audio.setVolume(150);
68             System.out.println("done");
69             System.out.println("Audio channel info: " + jvlc.audio.getChannel());
70             System.out.println("Audio track info: " + jvlc.audio.getTrack());
71             System.out.print("Setting left channel... ");
72             jvlc.audio.setChannel("left");
73             System.out.print("done.");
74             Thread.sleep(3000);
75             System.out.print("Setting right channel... ");
76             jvlc.audio.setChannel("right");
77             System.out.print("done.");
78             Thread.sleep(3000);
79             System.out.println("INPUT INFORMATION");
80             System.out.println("-----------------");
81             System.out.println("Total length   (ms) :\t" + jvlc.input.getLength());
82             System.out.println("Input time     (ms) :\t" + jvlc.input.getTime());
83             System.out.println("Input position [0-1]:\t" + jvlc.input.getPosition());
84             if (videoInput)
85                 System.out.println("Input FPS          :\t" + jvlc.input.getFPS());
86            
87             
88         }
89         
90         catch (Exception e) 
91         {
92                 System.out.println("Something was wrong. I die :(.");
93             jvlc.destroy();
94             e.printStackTrace();
95         }
96         
97         System.out.println("Everything fine ;)");
98         System.out.println("Playing next item");
99         try {
100                 jvlc.playlist.next();
101         } catch (VLCException e) {
102                 e.printStackTrace();
103         }
104         
105         try {
106                 Thread.sleep(3000);
107         } catch (InterruptedException e) {
108                 e.printStackTrace();
109         }
110         jvlc.destroy();
111         return;
112     }
113 }
114