]> git.sesse.net Git - vlc/blob - bindings/java/org/videolan/jvlc/JVLC.java
Java bindings update.
[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  * 
9  * Created on 28-feb-2006
10  *
11  * $Id$
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2 of the
16  * License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public
24  * License along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26  * 
27  */
28
29
30 package org.videolan.jvlc;
31
32 /**
33  * @author little
34  *
35  */
36 public class JVLC implements JLibVLC, Runnable {
37     
38     static {
39         System.load(System.getProperty( "user.dir" ) + "/libjvlc.so" );
40     }
41
42     /**
43      * These are set as final since they live along the jvlc object
44      */
45     private final long _instance;
46     public  final Playlist playlist;
47
48     
49     private boolean beingDestroyed = false;
50     private long resolution = 50;
51         private boolean inputPlaying = false;
52         private boolean inputVout = false;
53     
54     public JVLC() {
55         _instance = createInstance();
56         playlist = new Playlist( _instance );
57         new Thread(this).start();
58     }
59     
60     public JVLC(String[] args) {
61         _instance = createInstance( args );
62         playlist = new Playlist( _instance );
63         new Thread(this).start();
64     }
65     
66     
67     /**
68      * Destroys the current instance of jvlc, cleaning up objects.
69      * This is unreversible.
70      */
71     public void destroy() {
72         beingDestroyed = true;
73         _destroy();
74     }
75  
76
77         /*
78      * Core methods
79      */
80     private native long createInstance();
81     private native long createInstance( String[] args );
82     private native void _destroy();   
83     /*
84      *  Audio native methods
85      */
86     private native boolean      _getMute();
87     private native void         _setMute( boolean value );
88     private native void         _toggleMute();
89     private native int          _getVolume();
90     private native void         _setVolume( int volume );
91
92     /*
93      *  Input native methods
94      */
95     private native long     _getInputLength();
96     private native float    _getInputPosition();
97     private native long     _getInputTime();
98     private native float        _getInputFPS();
99
100     
101     /*
102      * Video native methods
103      */
104     private native void     _toggleFullscreen();
105     private native void     _setFullscreen( boolean value);
106     private native boolean  _getFullscreen();
107     private native int      _getVideoHeight();
108     private native int      _getVideoWidth();
109     private native void         _getSnapshot(String filename);
110  
111     
112     public boolean getMute() {
113         return _getMute();
114     }
115
116     public void setMute(boolean value) {
117         _setMute( value );
118         
119     }
120     
121     public void toggleMute() {
122         _toggleMute();
123     }
124
125     public int getVolume() {
126         return _getVolume();        
127     }
128
129     public void setVolume(int volume) {
130         _setVolume( volume );
131         
132     }
133
134     public void toggleFullscreen() {
135         _toggleFullscreen();
136         
137     }
138
139     public void setFullscreen( boolean value ) {
140         _setFullscreen( value );
141         
142     }
143
144     public boolean getFullscreen() {
145         return _getFullscreen();        
146     }
147
148     public int getVideoHeight() {
149         return _getVideoHeight();
150     }
151     
152
153     public int getVideoWidth() {
154         return _getVideoWidth();        
155     }
156
157     
158     public long getInputLength() {
159         return _getInputLength();        
160     }
161
162     public long getInputTime() {
163         return _getInputTime();
164     }
165
166     public float getInputPosition() {
167         return _getInputPosition();
168         
169     }
170
171     public void setInputTime() {
172         // TODO Auto-generated method stub
173         
174     }
175
176     public double getInputFPS() {
177         return _getInputFPS();
178     }
179     
180     public long getInstance() {
181         return _instance;
182     }
183
184     /*
185      * Getters and setters
186      */
187         public Playlist getPlaylist() {
188                 return playlist;
189         }
190     
191
192         public void getSnapshot(String filename) {
193                 _getSnapshot(filename);
194         }
195         
196         /**
197          * Checks if the input is playing.
198          * @return True if there is a playing input.
199          */
200         public boolean isInputPlaying() {
201                 return inputPlaying;
202         }
203
204         /**
205          * Checks if the input has spawned a video window.
206          * @return True if there is a video window.
207          */
208         public boolean hasVout() {
209                 return inputVout;
210         }
211
212         /*
213          * (non-Javadoc)
214          * @see java.lang.Runnable#run()
215          * 
216          * In this thread we check the playlist and input status.
217          */
218         public void run() {
219                 while (! beingDestroyed) {
220                         while (playlist.isRunning()) {
221                                 if (playlist.inputIsPlaying()) {
222                                         inputPlaying = true;
223                                 }
224                                 else {
225                                         inputPlaying = false;
226                 }
227                             
228                                 if (playlist.inputHasVout()) {
229                                         inputVout = true;
230                 }
231                                 else {
232                                         inputVout = false;
233                 }
234                                 try {
235                                         Thread.sleep(resolution);
236                                 } catch (InterruptedException e) {
237                                         e.printStackTrace();
238                                 } 
239                         } // while playlist running
240                    inputPlaying = false;
241                    inputVout = false;
242                         try {
243                                 Thread.sleep(resolution);
244                         } catch (InterruptedException e) {
245                                 e.printStackTrace();
246                         } // try
247                 } // while ! being destroyed
248         } // run
249
250 }
251