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