]> git.sesse.net Git - vlc/blob - bindings/java/VLCExample.java
Initial callback support in libvlc + example on how to use in the java bindings
[vlc] / bindings / java / VLCExample.java
1 import org.videolan.jvlc.AudioIntf;
2 import org.videolan.jvlc.JVLC;
3 import org.videolan.jvlc.VLCException;
4 import org.videolan.jvlc.VolumeListener;
5
6
7 public class VLCExample
8 {
9
10     public static void main(String[] args) throws InterruptedException
11     {
12         System.out.println("== Starting VLCExample ==");
13         boolean videoInput = false;
14         if (args.length == 0)
15         {
16             System.out.print("Creating a JVLC instance without args");
17         }
18         else
19         {
20             System.out.println("Creating a JVLC instance with args: ");
21             for (int i = 0; i < args.length; i++)
22             {
23                 System.out.println(i + ") " + args[i]);
24             }
25         }
26         JVLC jvlc = new JVLC(args);
27         System.out.println("... done.");
28
29         try
30         {
31             // jvlc.playlist.add("file://" + System.getProperty( "user.dir" ) + "/a.avi", "a.avi");
32             jvlc.playlist.add("file:///home/little/a.avi", "a.avi");
33             // jvlc.playlist.add("file://" + System.getProperty( "user.dir" ) + "/a.mp3", "a.mp3");
34             jvlc.playlist.play(-1, null);
35         }
36         catch (VLCException e)
37         {
38             e.printStackTrace();
39         }
40
41         while (! jvlc.isInputPlaying())
42         {
43             Thread.sleep(100);
44         }
45         while (! jvlc.hasVout() )
46         {
47             Thread.sleep(100);
48         }
49
50         // testing vout functionalities
51         Thread.sleep(2500);
52         if (jvlc.hasVout())
53         {
54             videoInput = true;
55         }
56         
57         if (videoInput)
58         {
59             try
60             {
61                 System.out.print(jvlc.video.getWidth());
62                 System.out.print("x");
63                 System.out.println(jvlc.video.getHeight());
64             }
65             catch (VLCException e)
66             {
67                 e.printStackTrace();
68             }
69         }
70         try
71         {
72             if (videoInput)
73             {
74                 System.out.print("Fullscreen... ");
75                 jvlc.video.setFullscreen(true);
76                 Thread.sleep(3000);
77                 System.out.println("real size.");
78                 jvlc.video.setFullscreen(false);
79                 System.out.print("Taking snapshot... ");
80                 jvlc.video.getSnapshot(System.getProperty("user.dir") + "/snap.png");
81                 System.out.println("taken. (see " + System.getProperty("user.dir") + "/snap.png )");
82                 Thread.sleep(2000);
83                 System.out.println("Resizing to 300x300");
84                 jvlc.video.setSize(300, 300);
85
86             }
87             jvlc.audio.addVolumeListener(new VolumeListener()
88             {
89                                 public void volumeChanged() {
90                                         System.out.println("====> From the listener: volume changed");
91                                 }
92             });
93
94             System.out.print("Muting...");
95             jvlc.audio.setMute(true);
96             Thread.sleep(3000);
97             System.out.println("unmuting.");
98             jvlc.audio.setMute(false);
99             Thread.sleep(3000);
100             System.out.println("Volume is: " + jvlc.audio.getVolume());
101             System.out.print("Setting volume to 150... ");
102             jvlc.audio.setVolume(150);
103             System.out.println("done");
104             System.out.println("== AUDIO INFO ==");
105             int currentChannel = jvlc.audio.getChannel();
106             System.out.println("Audio track number: " + jvlc.audio.getTrack());
107             System.out.println("Audio channel info: " + jvlc.audio.getChannel());
108             System.out.print("Setting left channel... ");
109             jvlc.audio.setChannel(AudioIntf.LEFT_CHANNEL);
110             System.out.println("done.");
111             Thread.sleep(3000);
112             System.out.print("Setting right channel... ");
113             jvlc.audio.setChannel(AudioIntf.RIGHT_CHANNEL);
114             System.out.println("done.");
115             Thread.sleep(3000);
116             System.out.print("Reverting to original channel");
117             jvlc.audio.setChannel(currentChannel);
118             System.out.println("done.");
119             Thread.sleep(3000);
120             System.out.println("INPUT INFORMATION");
121             System.out.println("-----------------");
122             System.out.println("Total length   (ms) :\t" + jvlc.input.getLength());
123             System.out.println("Input time     (ms) :\t" + jvlc.input.getTime());
124             System.out.println("Input position [0-1]:\t" + jvlc.input.getPosition());
125             if (videoInput)
126                 System.out.println("Input FPS          :\t" + jvlc.input.getFPS());
127
128         }
129
130         catch (Exception e)
131         {
132             System.out.println("Something was wrong. I die :(.");
133             jvlc.destroy();
134             e.printStackTrace();
135             System.exit(0);
136         }
137
138         System.out.println("Everything fine ;)");
139         System.out.println("Playing next item");
140         try
141         {
142             jvlc.playlist.next();
143         }
144         catch (VLCException e)
145         {
146             e.printStackTrace();
147         }
148
149         Thread.sleep(3000);
150
151         jvlc.destroy();
152         return;
153     }
154 }