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