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