]> git.sesse.net Git - vlc/blob - bindings/java/org/videolan/jvlc/JVLC.java
Sync bindings/java with jvlc head (release is close ;).
[vlc] / bindings / java / org / videolan / jvlc / JVLC.java
1 /*****************************************************************************
2  * JVLC.java: Main Java Class, represents a libvlc_instance_t object
3  *****************************************************************************
4  *
5  * Copyright (C) 1998-2006 the VideoLAN team
6  * 
7  * Author: Filippo Carone <filippo@carone.org>
8  *         Philippe Morin <phmorin@free.fr>
9  *
10  * Created on 28-feb-2006
11  *
12  * $Id$
13  *
14  * This program is free software; you can redistribute it
15  * and/or modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2 of the
17  * License, or (at your option) any later version.
18  * 
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22  * General Public License for more details.
23  * 
24  * You should have received a copy of the GNU General Public
25  * License along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
27  * 
28  */
29
30
31 package org.videolan.jvlc;
32
33 public class JVLC implements JLibVLC, Runnable {
34     
35     static {
36         System.loadLibrary("jvlc" );
37     }
38
39     /**
40      * These are set as final since they live along the jvlc object
41      */
42     private final long _instance;
43     public  final Playlist playlist;
44
45     
46     private boolean beingDestroyed = false;
47
48     /**
49      * This is the time in millis VLC checks for internal status 
50      */
51     private long resolution = 50;
52     
53         private boolean inputPlaying = false;
54         private boolean inputVout = false;
55     
56     public JVLC() {
57         String[] args = new String[1];
58         args[0] = "";
59         
60         _instance = createInstance(args);
61         playlist = new Playlist( _instance );
62         new Thread(this).start();
63     }
64     
65     public JVLC(String[] args) {
66         _instance = createInstance( args );
67         playlist = new Playlist( _instance );
68         new Thread(this).start();
69     }
70     
71     
72     /**
73      * Destroys the current instance of jvlc, cleaning up objects.
74      * This is unreversible.
75      */
76     public void destroy() {
77         beingDestroyed = true;
78         _destroy();
79     }
80  
81
82         /*
83      * Core methods
84      */
85     private native long createInstance();
86     private native long createInstance( String[] args );
87     private native void _destroy();   
88     /*
89      *  Audio native methods
90      */
91     private native boolean      _getMute();
92     private native void         _setMute( boolean value );
93     private native void         _toggleMute();
94     private native int          _getVolume();
95     private native void         _setVolume( int volume );
96
97     /*
98      *  Input native methods
99      */
100     private native long     _getInputLength();
101     private native float    _getInputPosition();
102     private native long     _getInputTime();
103     private native float        _getInputFPS();
104
105     
106     /*
107      * Video native methods
108      */
109     private native void     _toggleFullscreen();
110     private native void     _setFullscreen( boolean value);
111     private native boolean  _getFullscreen();
112     private native int      _getVideoHeight();
113     private native int      _getVideoWidth();
114     private native void         _getSnapshot(String filename);
115  
116
117     /*
118      * VLM native methods
119      */
120     private native void _addBroadcast(String mediaName, String meditInputMRL, String mediaOutputMRL ,
121                                String[] additionalOptions, boolean enableBroadcast, boolean isPlayableInLoop);
122     private native void _deleteMedia    (String mediaName);
123     private native void _setEnabled             (String mediaName,      boolean newStatus);
124     private native void _setOutput              (String mediaName,      String mediaOutputMRL);
125     private native void _setInput               (String mediaName,      String mediaInputMRL);
126     private native void _setLoop                (String mediaName,      boolean isPlayableInLoop);
127     private native void _changeMedia    (String newMediaName, String inputMRL, String outputMRL , String[] additionalOptions, boolean enableNewBroadcast, boolean isPlayableInLoop);
128
129     /*
130      * Native methods wrappers
131      */
132        
133     
134     public boolean getMute() throws VLCException {
135         return _getMute();
136     }
137
138     public void setMute(boolean value) throws VLCException {
139         _setMute( value );
140         
141     }
142     
143     public void toggleMute() throws VLCException {
144         _toggleMute();
145     }
146
147     public int getVolume() throws VLCException {
148         return _getVolume();        
149     }
150
151     public void setVolume(int volume) throws VLCException {
152         _setVolume( volume );
153         
154     }
155
156     public void toggleFullscreen() throws VLCException {
157         _toggleFullscreen();
158         
159     }
160
161     public void setFullscreen( boolean value ) throws VLCException {
162         _setFullscreen( value );
163         
164     }
165
166     public boolean getFullscreen() throws VLCException {
167         return _getFullscreen();        
168     }
169
170     public int getVideoHeight() throws VLCException {
171         return _getVideoHeight();
172     }
173     
174
175     public int getVideoWidth() throws VLCException {
176         return _getVideoWidth();        
177     }
178
179     
180     public long getInputLength() throws VLCException {
181         return _getInputLength();        
182     }
183
184     public long getInputTime() throws VLCException {
185         return _getInputTime();
186     }
187
188     public float getInputPosition() throws VLCException {
189         return _getInputPosition();
190         
191     }
192
193     public void setInputTime() throws VLCException {
194         // TODO Auto-generated method stub
195         
196     }
197
198     public double getInputFPS() throws VLCException {
199         return _getInputFPS();
200     }
201     
202     public long getInstance() throws VLCException {
203         return _instance;
204     }
205
206     /*
207      * Getters and setters
208      */
209         public Playlist getPlaylist() throws VLCException {
210                 return playlist;
211         }
212     
213
214         public void getSnapshot(String filename) throws VLCException {
215                 _getSnapshot(filename);
216         }
217
218
219     public void addBroadcast( String name, String input, String output, String[] options, boolean enabled, boolean loop )
220         throws VLCException {
221         _addBroadcast(name, input, output, options, enabled, loop);
222     }
223     
224     public void deleteMedia( String name ) throws VLCException {
225         _deleteMedia(name);
226     }
227     
228     public void setEnabled( String name, boolean enabled ) throws VLCException {
229         _setEnabled(name, enabled);
230     }
231     
232     public void setOutput( String name, String output ) throws VLCException {
233         _setOutput(name, output);
234     }
235     
236     public void setInput( String name, String input ) throws VLCException {
237         _setInput(name, input);
238     }
239     
240     public void setLoop( String name, boolean loop ) throws VLCException {
241         _setLoop(name, loop);
242     }
243     
244     public void changeMedia( String name, String input, String output, String[] options, boolean enabled, boolean loop )
245         throws VLCException {
246         _changeMedia(name, input, output, options, enabled, loop);
247     }
248
249         
250         /**
251          * Checks if the input is playing.
252          * @return True if there is a playing input.
253          */
254         public boolean isInputPlaying() {
255                 return inputPlaying;
256         }
257
258         /**
259          * Checks if the input has spawned a video window.
260          * @return True if there is a video window.
261          */
262         public boolean hasVout() {
263                 return inputVout;
264         }
265
266         /*
267          * (non-Javadoc)
268          * @see java.lang.Runnable#run()
269          * 
270          * In this thread we check the playlist and input status.
271          */
272         public void run() {
273                 while (! beingDestroyed) {
274                         try {
275                                 while (playlist.isRunning()) {
276                                         if (playlist.inputIsPlaying()) {
277                                                 inputPlaying = true;
278                                         }
279                                         else {
280                                                 inputPlaying = false;
281                                     }
282                                             
283                                         if (playlist.inputHasVout()) {
284                                                 inputVout = true;
285                                     }
286                                         else {
287                                                 inputVout = false;
288                                     }
289                                         try {
290                                                 Thread.sleep(resolution);
291                                         } catch (InterruptedException e) {
292                                                 e.printStackTrace();
293                                         } 
294                                 }
295                         } catch (VLCException e1) { } // while playlist running
296                    inputPlaying = false;
297                    inputVout = false;
298                         try {
299                                 Thread.sleep(resolution);
300                         } catch (InterruptedException e) {
301                                 e.printStackTrace();
302                         } // try
303                 } // while ! being destroyed
304         } // run
305
306 }
307