]> git.sesse.net Git - vlc/blob - bindings/java/core/src/main/java/org/videolan/jvlc/JVLC.java
7ffaa18e0eb6be403a23982cd617c5338d5ab5eb
[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 org.videolan.jvlc.internal.LibVlc;
33 import org.videolan.jvlc.internal.LibVlc.LibVlcInstance;
34 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
35
36 import com.sun.jna.Native;
37
38 import java.awt.Canvas;
39
40 public class JVLC
41 {
42
43     private final LibVlcInstance instance;
44
45     private final LibVlc libvlc = LibVlc.SYNC_INSTANCE;
46     
47     public JVLC()
48     {
49         String[] args = new String[1];
50         args[0] = "jvlc";
51         instance = createInstance(args);
52     }
53
54     public JVLC(String[] args)
55     {
56         String[] myargs = new String[args.length + 1];
57         myargs[0] = "jvlc";
58         System.arraycopy(args, 0, myargs, 1, args.length);
59         instance = createInstance(myargs);
60     }
61
62     public MediaInstance play(String media)
63     {
64         MediaDescriptor mediaDescriptor = new MediaDescriptor(this, media);
65         MediaInstance mediaInstance = new MediaInstance(mediaDescriptor);
66         mediaInstance.play();
67         return mediaInstance;
68     }
69
70     public void setVideoOutput(Canvas canvas)
71     {
72         long drawable = Native.getComponentID(canvas);
73         libvlc_exception_t exception = new libvlc_exception_t();
74         libvlc.libvlc_video_set_parent(instance, drawable, exception );
75     }
76
77     /*
78      * Core methods
79      */
80     private LibVlcInstance createInstance(String[] args)
81     {
82         libvlc_exception_t exception = new libvlc_exception_t();
83         libvlc.libvlc_exception_init(exception);
84
85         return libvlc.libvlc_new(args.length, args, exception);
86     }
87
88     /**
89      * Returns the _instance.
90      * @return the _instance
91      */
92     LibVlcInstance getInstance()
93     {
94         return instance;
95     }
96
97     /**
98      * Returns the libvlc.
99      * @return the libvlc
100      */
101     LibVlc getLibvlc()
102     {
103         return libvlc;
104     }
105
106     /*
107      * (non-Javadoc)
108      * @see java.lang.Object#finalize()
109      */
110     @Override
111     protected void finalize() throws Throwable
112     {
113         libvlc.libvlc_release(instance);
114         super.finalize();
115     }
116 }