]> git.sesse.net Git - vlc/blob - bindings/java/core/src/main/java/org/videolan/jvlc/JVLC.java
jvlc: audio is an instance property
[vlc] / bindings / java / core / src / main / 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-2008 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: JVLC.java 20141 2007-05-16 19:31:35Z littlejohn $
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 package org.videolan.jvlc;
31
32 import java.awt.Canvas;
33
34 import org.videolan.jvlc.internal.LibVlc;
35 import org.videolan.jvlc.internal.LibVlc.LibVlcInstance;
36 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
37
38 import com.sun.jna.Native;
39
40 public class JVLC
41 {
42
43     private final LibVlcInstance instance;
44
45     private final LibVlc libvlc = LibVlc.SYNC_INSTANCE;
46
47     private MediaList mediaList;
48     
49     private VLM vlm;
50     
51     private Audio audio;
52     
53     private volatile boolean released;
54
55     private MediaListPlayer mediaListPlayer;
56     
57     public JVLC()
58     {
59         String[] args = new String[] {};
60         instance = createInstance(args);
61         init();
62     }
63
64     public JVLC(String[] args)
65     {
66         instance = createInstance(args);
67         init();
68     }
69     
70     private void init()
71     {
72         mediaList = new MediaList(this);
73         mediaListPlayer = new MediaListPlayer(this);
74         mediaListPlayer.setMediaList(mediaList);
75         audio = new Audio(this);
76     }
77     
78     public JVLC(String args)
79     {
80         this(args.split(" "));
81     }
82
83     /*
84      * Core methods
85      */
86     private LibVlcInstance createInstance(String[] args)
87     {
88         libvlc_exception_t exception = new libvlc_exception_t();
89         return libvlc.libvlc_new(args.length, args, exception);
90     }
91
92     public MediaPlayer play(String media)
93     {
94         MediaDescriptor mediaDescriptor = new MediaDescriptor(this, media);
95         MediaPlayer mediaPlayer = new MediaPlayer(mediaDescriptor);
96         mediaPlayer.play();
97         mediaDescriptor.release();
98         return mediaPlayer;
99     }
100
101     public void setVideoOutput(Canvas canvas)
102     {
103         long drawable = Native.getComponentID(canvas);
104         libvlc_exception_t exception = new libvlc_exception_t();
105         libvlc.libvlc_video_set_parent(instance, drawable, exception );
106     }
107
108     public Logger getLogger()
109     {
110         return new Logger(this);
111     }
112     
113     /**
114      * Returns the mediaList.
115      * @return the mediaList
116      */
117     public MediaList getMediaList()
118     {
119         return mediaList;
120     }
121
122     public VLM getVLM()
123     {
124         if (vlm != null)
125         {
126             vlm.release();
127         }
128         this.vlm = new VLM(this);
129         return vlm;
130     }
131     
132     public LoggerVerbosityLevel getLogVerbosity()
133     {
134         libvlc_exception_t exception = new libvlc_exception_t();
135         int level = libvlc.libvlc_get_log_verbosity(instance, exception);
136         return LoggerVerbosityLevel.getSeverity(level);
137     }
138
139     public void setLogVerbosity(LoggerVerbosityLevel level)
140     {
141         libvlc_exception_t exception = new libvlc_exception_t();
142         libvlc.libvlc_set_log_verbosity(instance, level.ordinal(), exception);
143     }
144
145     
146     /**
147      * Returns the _instance.
148      * @return the _instance
149      */
150     LibVlcInstance getInstance()
151     {
152         return instance;
153     }
154
155     /**
156      * Returns the libvlc.
157      * @return the libvlc
158      */
159     LibVlc getLibvlc()
160     {
161         return libvlc;
162     }
163     
164     /**
165      * Releases this instance and the native resources.
166      */
167     public void release()
168     {
169         if (released)
170         {
171             return;
172         }
173         released = true;
174         if (vlm != null)
175         {
176             vlm.release();
177             vlm = null;
178         }
179         libvlc.libvlc_release(instance);
180     }
181
182     /*
183      * (non-Javadoc)
184      * @see java.lang.Object#finalize()
185      */
186     @Override
187     protected void finalize() throws Throwable
188     {
189         release();
190         super.finalize();
191     }
192
193     
194     /**
195      * Returns the mediaListPlayer.
196      * @return the mediaListPlayer
197      */
198     public MediaListPlayer getMediaListPlayer()
199     {
200         return mediaListPlayer;
201     }
202
203     /**
204      * @return
205      */
206     public Audio getAudio()
207     {
208         return audio;
209     }
210     
211 }