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