]> git.sesse.net Git - vlc/blob - bindings/java/org/videolan/jvlc/internal/LibVlcImpl.java
ff78ad75cc7f90ff24d17b2ce1b7b5a434298302
[vlc] / bindings / 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 import java.awt.Component;
30
31 import javax.swing.JFrame;
32 import javax.swing.JPanel;
33
34 import org.videolan.jvlc.internal.LibVlc.LibVlcCallback;
35 import org.videolan.jvlc.internal.LibVlc.LibVlcEventManager;
36 import org.videolan.jvlc.internal.LibVlc.LibVlcInstance;
37 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor;
38 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaInstance;
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.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         LibVlcInstance libvlc_instance_t = libVlc.libvlc_new(0, new String[] {"/usr/local/bin/vlc"}, exception);
59
60         LibVlcMediaDescriptor mediaDescriptor = libVlc
61             .libvlc_media_descriptor_new(libvlc_instance_t, "/home/carone/a.avi", exception);
62
63         LibVlcMediaInstance mediaInstance = libVlc.libvlc_media_instance_new_from_media_descriptor(mediaDescriptor, exception);
64
65         LibVlcEventManager mediaInstanceEventManager = libVlc.libvlc_media_instance_event_manager(mediaInstance, exception);
66
67         LibVlcCallback played = new LibVlcCallback()
68         {
69
70             @Override
71             public void callback(int libvlc_event_t, Pointer pointer)
72             {
73                 System.out.println("Playing started.");
74             }
75         };
76
77         LibVlcCallback endReached = new LibVlcCallback()
78         {
79
80             @Override
81             public void callback(int libvlc_event_t, Pointer pointer)
82             {
83                 synchronized (lock)
84                 {
85                     System.out.println("Playing finished.");
86                     LibVlcImpl.done = true;
87                 }
88             }
89         };
90
91         libVlc.libvlc_event_attach(
92             mediaInstanceEventManager,
93             LibVlcEventType.libvlc_MediaInstancePlayed.ordinal(),
94             played,
95             null,
96             exception);
97
98         libVlc.libvlc_event_attach(
99             mediaInstanceEventManager,
100             LibVlcEventType.libvlc_MediaInstanceReachedEnd.ordinal(),
101             endReached,
102             null,
103             exception);
104         
105         JFrame frame = new JFrame("title");
106         frame.setVisible(true);
107         frame.setLocation(100, 100);
108         frame.setSize(500, 500);
109         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
110         
111         JPanel panel = new JPanel();
112         Canvas canvas = new Canvas();
113         canvas.setSize(500, 500);
114         panel.add(canvas);
115         frame.getContentPane().add(panel);
116         frame.pack();
117         
118         long drawable = com.sun.jna.Native.getComponentID(canvas);
119         
120         libVlc.libvlc_video_set_parent(libvlc_instance_t, drawable, exception);
121
122         libVlc.libvlc_media_instance_play(mediaInstance, exception);
123     }
124 }