]> git.sesse.net Git - vlc/blob - bindings/java/core/src/main/java/org/videolan/jvlc/VLM.java
protect from null options param, and finalize added
[vlc] / bindings / java / core / src / main / java / org / videolan / jvlc / VLM.java
1 /*****************************************************************************
2  * VLM.java: VLC Java Bindings
3  *****************************************************************************
4  * Copyright (C) 1998-2008 the VideoLAN team
5  *
6  * Authors: Filippo Carone <filippo@carone.org>
7  *
8  *
9  * $Id $
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 package org.videolan.jvlc;
27
28 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
29
30
31 public class VLM
32 {
33
34     private JVLC jvlc;
35     
36     private volatile boolean released;
37
38     public VLM(JVLC jvlc)
39     {
40         this.jvlc = jvlc;
41     }
42
43     public void addBroadcast(String name, String input, String output, String[] options, boolean enabled, boolean loop)
44     {
45         libvlc_exception_t exception = new libvlc_exception_t();
46         jvlc.getLibvlc().libvlc_vlm_add_broadcast(
47             jvlc.getInstance(),
48             name,
49             input,
50             output,
51             options == null ? 0 : options.length,
52             options,
53             enabled ? 1 : 0,
54             loop ? 1 : 0,
55             exception);
56     }
57
58     public void deleteMedia(String name)
59     {
60         libvlc_exception_t exception = new libvlc_exception_t();
61         jvlc.getLibvlc().libvlc_vlm_del_media(jvlc.getInstance(), name, exception);
62     }
63
64     public void enableMedia(String name)
65     {
66         libvlc_exception_t exception = new libvlc_exception_t();
67         jvlc.getLibvlc().libvlc_vlm_set_enabled(jvlc.getInstance(), name, 1, exception);
68     }
69
70     public void disableMedia(String name)
71     {
72         libvlc_exception_t exception = new libvlc_exception_t();
73         jvlc.getLibvlc().libvlc_vlm_set_enabled(jvlc.getInstance(), name, 0, exception);
74     }
75
76     public void setMediaOutput(String name, String output)
77     {
78         libvlc_exception_t exception = new libvlc_exception_t();
79         jvlc.getLibvlc().libvlc_vlm_set_output(jvlc.getInstance(), name, output, exception);
80     }
81
82     public void setMediaInput(String name, String input)
83     {
84         libvlc_exception_t exception = new libvlc_exception_t();
85         jvlc.getLibvlc().libvlc_vlm_set_input(jvlc.getInstance(), name, input, exception);
86     }
87
88     public void addMediaInput(String name, String input)
89     {
90         libvlc_exception_t exception = new libvlc_exception_t();
91         jvlc.getLibvlc().libvlc_vlm_add_input(jvlc.getInstance(), name, input, exception);
92     }
93
94     public void setMediaLoop(String media, boolean loop)
95     {
96         libvlc_exception_t exception = new libvlc_exception_t();
97         jvlc.getLibvlc().libvlc_vlm_set_loop(jvlc.getInstance(), media, loop ? 1 : 0, exception);
98     }
99
100     public void changeMedia(String name, String input, String output, String[] options, boolean enabled, boolean loop)
101     {
102         libvlc_exception_t exception = new libvlc_exception_t();
103         jvlc.getLibvlc().libvlc_vlm_change_media(
104             jvlc.getInstance(),
105             name,
106             input,
107             output,
108             options == null ? 0 : options.length,
109             options,
110             enabled ? 1 : 0,
111             loop ? 1 : 0,
112             exception);
113     }
114
115     public void playMedia(String name)
116     {
117         libvlc_exception_t exception = new libvlc_exception_t();
118         jvlc.getLibvlc().libvlc_vlm_play_media(jvlc.getInstance(), name, exception);
119     }
120
121     public void stopMedia(String name)
122     {
123         libvlc_exception_t exception = new libvlc_exception_t();
124         jvlc.getLibvlc().libvlc_vlm_stop_media(jvlc.getInstance(), name, exception);
125     }
126
127     public void pauseMedia(String name)
128     {
129         libvlc_exception_t exception = new libvlc_exception_t();
130         jvlc.getLibvlc().libvlc_vlm_pause_media(jvlc.getInstance(), name, exception);
131     }
132
133     public void seekMedia(String name, float percentage)
134     {
135         libvlc_exception_t exception = new libvlc_exception_t();
136         jvlc.getLibvlc().libvlc_vlm_seek_media(jvlc.getInstance(), name, percentage, exception);
137     }
138
139     public void showMedia(String name)
140     {
141         libvlc_exception_t exception = new libvlc_exception_t();
142         jvlc.getLibvlc().libvlc_vlm_show_media(jvlc.getInstance(), name, exception);
143     }
144
145     /**
146      * Releases native resources related to VLM.
147      */
148     public void release()
149     {
150         if (released)
151         {
152             return;
153         }
154         released = true;
155         libvlc_exception_t exception = new libvlc_exception_t();
156         jvlc.getLibvlc().libvlc_vlm_release(jvlc.getInstance(), exception);
157     }
158
159     /**
160      * {@inheritDoc}
161      */
162     @Override
163     protected void finalize() throws Throwable
164     {
165         release();
166         super.finalize();
167     }
168     
169     
170
171 }