]> git.sesse.net Git - vlc/blob - bindings/java/org/videolan/jvlc/JVLC.java
71ed3ffb0e580ce4f696c6eb74f04be9a32bc563
[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         _instance       = createInstance( args );
76         playlist        = new Playlist  ( _instance );
77         video           = new Video             ( _instance );
78         audio           = new Audio             ( _instance );
79         input           = new Input             ( _instance );
80         vlm                     = new VLM               ( _instance );
81         
82         new Thread(this).start();
83     }
84     
85     
86     /**
87      * Destroys the current instance of jvlc, cleaning up objects.
88      * This is unreversible.
89      */
90     public void destroy() {
91         beingDestroyed = true;
92         _destroy();
93     }
94  
95
96         /*
97      * Core methods
98      */
99     private native long createInstance( String[] args );
100     private native void _destroy();   
101
102     public long getInstance() throws VLCException {
103         return _instance;
104     }
105
106     /*
107      * Getters and setters
108      */
109         public Playlist getPlaylist() throws VLCException {
110                 return playlist;
111         }
112     
113
114
115         /**
116          * Checks if the input is playing.
117          * @return True if there is a playing input.
118          */
119         public boolean isInputPlaying() {
120                 return inputPlaying;
121         }
122
123         /**
124          * Checks if the input has spawned a video window.
125          * @return True if there is a video window.
126          */
127         public boolean hasVout() {
128                 return inputVout;
129         }
130
131         /*
132          * (non-Javadoc)
133          * @see java.lang.Runnable#run()
134          * 
135          * In this thread we check the playlist and input status.
136          */
137         public void run() {
138                 while (! beingDestroyed) {
139                         try {
140                                 while (playlist.isRunning()) {
141                                         if (input.isPlaying()) {
142                                                 inputPlaying = true;
143                                         }
144                                         else {
145                                                 inputPlaying = false;
146                                     }
147                                             
148                                         if (input.hasVout()) {
149                                                 inputVout = true;
150                                     }
151                                         else {
152                                                 inputVout = false;
153                                     }
154                                         try {
155                                                 Thread.sleep(resolution);
156                                         } catch (InterruptedException e) {
157                                                 e.printStackTrace();
158                                         } 
159                                 }
160                         } catch (VLCException e1) { } // while playlist running
161                    inputPlaying = false;
162                    inputVout = false;
163                         try {
164                                 Thread.sleep(resolution);
165                         } catch (InterruptedException e) {
166                                 e.printStackTrace();
167                         } // try
168                 } // while ! being destroyed
169         } // run
170 }
171