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