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