]> git.sesse.net Git - vlc/blob - bindings/java/core/src/main/java/org/videolan/jvlc/internal/LibVlcImpl.java
jvlc: fix the native type for drawable
[vlc] / bindings / java / core / src / main / java / org / videolan / jvlc / internal / LibVlcImpl.java
1 /*****************************************************************************
2  * ${file_name}: VLC Java Bindings
3  *****************************************************************************
4  * Copyright (C) 1998-2007 the VideoLAN team
5  *
6  * Authors: Filippo Carone <filippo@carone.org>
7  *
8  *
9  * $Id $
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 package org.videolan.jvlc.internal;
27
28 import java.awt.Canvas;
29
30 import javax.swing.JFrame;
31 import javax.swing.JPanel;
32
33 import org.videolan.jvlc.internal.LibVlc.LibVlcCallback;
34 import org.videolan.jvlc.internal.LibVlc.LibVlcEventManager;
35 import org.videolan.jvlc.internal.LibVlc.LibVlcInstance;
36 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor;
37 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaInstance;
38 import org.videolan.jvlc.internal.LibVlc.libvlc_event_t;
39 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
40
41 import com.sun.jna.Pointer;
42
43
44 public class LibVlcImpl
45 {
46
47     public static boolean done;
48
49     public static void main(String[] args) throws InterruptedException
50     {
51         LibVlc libVlc = LibVlc.SYNC_INSTANCE;
52         libvlc_exception_t exception = new libvlc_exception_t();
53         libVlc.libvlc_exception_init(exception);
54
55         final Object lock = new Object();
56
57         System.out.println("Starting vlc");
58         System.out.println("version: " + libVlc.libvlc_get_version());
59         System.out.println("changeset: " + libVlc.libvlc_get_changeset());
60         System.out.println("compiler: " + libVlc.libvlc_get_compiler());
61         
62         LibVlcInstance libvlc_instance_t = libVlc.libvlc_new(0, new String[] {"/usr/local/bin/vlc"}, exception);
63
64         LibVlcMediaDescriptor mediaDescriptor = libVlc
65             .libvlc_media_new(libvlc_instance_t, "/home/carone/a.avi", exception);
66
67         LibVlcMediaInstance mediaPlayer = libVlc.libvlc_media_player_new_from_media(mediaDescriptor, exception);
68
69         LibVlcEventManager mediaInstanceEventManager = libVlc.libvlc_media_player_event_manager(mediaPlayer, exception);
70
71         LibVlcCallback played = new LibVlcCallback()
72         {
73
74             public void callback(libvlc_event_t libvlc_event_t, Pointer pointer)
75             {
76                 System.out.println("Playing started.");
77             }
78         };
79
80         LibVlcCallback endReached = new LibVlcCallback()
81         {
82
83             public void callback(libvlc_event_t libvlc_event_t, Pointer pointer)
84             {
85                 synchronized (lock)
86                 {
87                     System.out.println("Playing finished.");
88                     LibVlcImpl.done = true;
89                 }
90             }
91         };
92
93         libVlc.libvlc_event_attach(
94             mediaInstanceEventManager,
95             LibVlcEventType.libvlc_MediaPlayerPlayed.ordinal(),
96             played,
97             null,
98             exception);
99
100         libVlc.libvlc_event_attach(
101             mediaInstanceEventManager,
102             LibVlcEventType.libvlc_MediaPlayerEndReached.ordinal(),
103             endReached,
104             null,
105             exception);
106
107         JFrame frame = new JFrame("title");
108         frame.setVisible(true);
109         frame.setLocation(100, 100);
110         frame.setSize(500, 500);
111         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
112         
113         JPanel panel = new JPanel();
114         Canvas canvas = new Canvas();
115         canvas.setSize(500, 500);
116         panel.add(canvas);
117         frame.getContentPane().add(panel);
118         frame.pack();
119         
120         int drawable = (int) com.sun.jna.Native.getComponentID(canvas);
121
122         libVlc.libvlc_video_set_parent(libvlc_instance_t, drawable, exception);
123         libVlc.libvlc_media_player_play(mediaPlayer, exception);
124     }
125 }