1 /*****************************************************************************
2 * JVLC.java: Main Java Class, represents a libvlc_instance_t object
3 *****************************************************************************
5 * Copyright (C) 1998-2006 the VideoLAN team
7 * Author: Filippo Carone <filippo@carone.org>
8 * Philippe Morin <phmorin@free.fr>
10 * Created on 28-feb-2006
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.
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.
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.
31 package org.videolan.jvlc;
33 public class JVLC implements JLibVLC, Runnable {
36 System.loadLibrary("jvlc" );
40 * These are set as final since they live along the jvlc object
42 private final long _instance;
43 public final Playlist playlist;
46 private boolean beingDestroyed = false;
49 * This is the time in millis VLC checks for internal status
51 private long resolution = 50;
53 private boolean inputPlaying = false;
54 private boolean inputVout = false;
57 String[] args = new String[1];
60 _instance = createInstance(args);
61 playlist = new Playlist( _instance );
62 new Thread(this).start();
65 public JVLC(String[] args) {
66 _instance = createInstance( args );
67 playlist = new Playlist( _instance );
68 new Thread(this).start();
73 * Destroys the current instance of jvlc, cleaning up objects.
74 * This is unreversible.
76 public void destroy() {
77 beingDestroyed = true;
85 private native long createInstance();
86 private native long createInstance( String[] args );
87 private native void _destroy();
89 * Audio native methods
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 );
98 * Input native methods
100 private native long _getInputLength();
101 private native float _getInputPosition();
102 private native long _getInputTime();
103 private native float _getInputFPS();
107 * Video native methods
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);
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);
130 * Native methods wrappers
134 public boolean getMute() throws VLCException {
138 public void setMute(boolean value) throws VLCException {
143 public void toggleMute() throws VLCException {
147 public int getVolume() throws VLCException {
151 public void setVolume(int volume) throws VLCException {
152 _setVolume( volume );
156 public void toggleFullscreen() throws VLCException {
161 public void setFullscreen( boolean value ) throws VLCException {
162 _setFullscreen( value );
166 public boolean getFullscreen() throws VLCException {
167 return _getFullscreen();
170 public int getVideoHeight() throws VLCException {
171 return _getVideoHeight();
175 public int getVideoWidth() throws VLCException {
176 return _getVideoWidth();
180 public long getInputLength() throws VLCException {
181 return _getInputLength();
184 public long getInputTime() throws VLCException {
185 return _getInputTime();
188 public float getInputPosition() throws VLCException {
189 return _getInputPosition();
193 public void setInputTime() throws VLCException {
194 // TODO Auto-generated method stub
198 public double getInputFPS() throws VLCException {
199 return _getInputFPS();
202 public long getInstance() throws VLCException {
207 * Getters and setters
209 public Playlist getPlaylist() throws VLCException {
214 public void getSnapshot(String filename) throws VLCException {
215 _getSnapshot(filename);
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);
224 public void deleteMedia( String name ) throws VLCException {
228 public void setEnabled( String name, boolean enabled ) throws VLCException {
229 _setEnabled(name, enabled);
232 public void setOutput( String name, String output ) throws VLCException {
233 _setOutput(name, output);
236 public void setInput( String name, String input ) throws VLCException {
237 _setInput(name, input);
240 public void setLoop( String name, boolean loop ) throws VLCException {
241 _setLoop(name, loop);
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);
251 * Checks if the input is playing.
252 * @return True if there is a playing input.
254 public boolean isInputPlaying() {
259 * Checks if the input has spawned a video window.
260 * @return True if there is a video window.
262 public boolean hasVout() {
268 * @see java.lang.Runnable#run()
270 * In this thread we check the playlist and input status.
273 while (! beingDestroyed) {
275 while (playlist.isRunning()) {
276 if (playlist.inputIsPlaying()) {
280 inputPlaying = false;
283 if (playlist.inputHasVout()) {
290 Thread.sleep(resolution);
291 } catch (InterruptedException e) {
295 } catch (VLCException e1) { } // while playlist running
296 inputPlaying = false;
299 Thread.sleep(resolution);
300 } catch (InterruptedException e) {
303 } // while ! being destroyed