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