]> git.sesse.net Git - vlc/blob - bindings/java/org/videolan/jvlc/JVLC.java
better args handling
[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
34 public class JVLC implements Runnable {
35     
36     static {
37         System.loadLibrary("jvlc" );
38     }
39
40     /**
41      * These are set as final since they live along the jvlc object
42      */
43     private final long          _instance;
44     
45     public  final Playlist      playlist;
46     public      final Video             video;
47     public      final Audio             audio;
48     public      final Input             input;
49     public      final VLM               vlm;
50     
51     private boolean beingDestroyed = false;
52
53     /**
54      * This is the time in millis VLC checks for internal status 
55      */
56     private long resolution = 50;
57     
58         private boolean inputPlaying = false;
59         private boolean inputVout = false;
60     
61     public JVLC() {
62         String[] args = new String[1];
63         args[0] = "jvlc";
64         
65         _instance       = createInstance( args );
66         playlist        = new Playlist  ( _instance );
67         video           = new Video             ( _instance );
68         audio           = new Audio             ( _instance );
69         input           = new Input             ( _instance );
70         vlm                     = new VLM               ( _instance );
71         new Thread(this).start();
72     }
73     
74     public JVLC(String[] args) {
75         String[] myargs = new String[args.length + 1];
76         myargs[0] = "jvlc";
77         System.arraycopy( args, 0, myargs, 1, args.length );
78         _instance       = createInstance( myargs );
79         playlist        = new Playlist  ( _instance );
80         video           = new Video             ( _instance );
81         audio           = new Audio             ( _instance );
82         input           = new Input             ( _instance );
83         vlm                     = new VLM               ( _instance );
84         
85         new Thread(this).start();
86     }
87     
88     
89     /**
90      * Destroys the current instance of jvlc, cleaning up objects.
91      * This is unreversible.
92      */
93     public void destroy() {
94         beingDestroyed = true;
95         _destroy();
96     }
97  
98
99         /*
100      * Core methods
101      */
102     private native long createInstance( String[] args );
103     private native void _destroy();   
104
105     public long getInstance() throws VLCException {
106         return _instance;
107     }
108
109     /*
110      * Getters and setters
111      */
112         public Playlist getPlaylist() throws VLCException {
113                 return playlist;
114         }
115     
116
117
118         /**
119          * Checks if the input is playing.
120          * @return True if there is a playing input.
121          */
122         public boolean isInputPlaying() {
123                 return inputPlaying;
124         }
125
126         /**
127          * Checks if the input has spawned a video window.
128          * @return True if there is a video window.
129          */
130         public boolean hasVout() {
131                 return inputVout;
132         }
133
134         /*
135          * (non-Javadoc)
136          * @see java.lang.Runnable#run()
137          * 
138          * In this thread we check the playlist and input status.
139          */
140         public void run() {
141                 while (! beingDestroyed) {
142                         try {
143                                 while (playlist.isRunning()) {
144                                         if (input.isPlaying()) {
145                                                 inputPlaying = true;
146                                         }
147                                         else {
148                                                 inputPlaying = false;
149                                     }
150                                             
151                                         if (input.hasVout()) {
152                                                 inputVout = true;
153                                     }
154                                         else {
155                                                 inputVout = false;
156                                     }
157                                         try {
158                                                 Thread.sleep(resolution);
159                                         } catch (InterruptedException e) {
160                                                 e.printStackTrace();
161                                         } 
162                                 }
163                         } catch (VLCException e1) { } // while playlist running
164                    inputPlaying = false;
165                    inputVout = false;
166                         try {
167                                 Thread.sleep(resolution);
168                         } catch (InterruptedException e) {
169                                 e.printStackTrace();
170                         } // try
171                 } // while ! being destroyed
172         } // run
173 }
174