]> git.sesse.net Git - vlc/blob - bindings/java/core/src/main/java/org/videolan/jvlc/internal/LibVlcImpl.java
5a163f5d9e32ee2a2209c935eccafa70720e336c
[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 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_event_t;
40 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
41
42 import com.sun.jna.Pointer;
43
44
45 public class LibVlcImpl
46 {
47
48     public static boolean done;
49
50     public static void main(String[] args) throws InterruptedException
51     {
52         LibVlc libVlc = LibVlc.INSTANCE;
53         libvlc_exception_t exception = new libvlc_exception_t();
54         libVlc.libvlc_exception_init(exception);
55
56         final Object lock = new Object();
57
58         System.out.println("Starting vlc");
59         LibVlcInstance libvlc_instance_t = libVlc.libvlc_new(0, new String[] {"/usr/local/bin/vlc"}, exception);
60
61         LibVlcMediaDescriptor mediaDescriptor = libVlc
62             .libvlc_media_new(libvlc_instance_t, "/home/carone/a.avi", exception);
63
64         LibVlcMediaInstance mediaInstance = libVlc.libvlc_media_player_new_from_media(mediaDescriptor, exception);
65
66         LibVlcEventManager mediaInstanceEventManager = libVlc.libvlc_media_player_event_manager(mediaInstance, exception);
67
68         LibVlcCallback played = new LibVlcCallback()
69         {
70
71             public void callback(libvlc_event_t libvlc_event_t, Pointer pointer)
72             {
73                 System.out.println("Playing started.");
74             }
75         };
76
77         LibVlcCallback endReached = new LibVlcCallback()
78         {
79
80             public void callback(libvlc_event_t libvlc_event_t, Pointer pointer)
81             {
82                 synchronized (lock)
83                 {
84                     System.out.println("Playing finished.");
85                     LibVlcImpl.done = true;
86                 }
87             }
88         };
89
90         libVlc.libvlc_event_attach(
91             mediaInstanceEventManager,
92             LibVlcEventType.libvlc_MediaPlayerPlayed.ordinal(),
93             played,
94             null,
95             exception);
96
97         libVlc.libvlc_event_attach(
98             mediaInstanceEventManager,
99             LibVlcEventType.libvlc_MediaPlayerEndReached.ordinal(),
100             endReached,
101             null,
102             exception);
103
104         JFrame frame = new JFrame("title");
105         frame.setVisible(true);
106         frame.setLocation(100, 100);
107         frame.setSize(500, 500);
108         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
109         
110         JPanel panel = new JPanel();
111         Canvas canvas = new Canvas();
112         canvas.setSize(500, 500);
113         panel.add(canvas);
114         frame.getContentPane().add(panel);
115         frame.pack();
116         
117         long drawable = com.sun.jna.Native.getComponentID(canvas);
118         
119         libVlc.libvlc_video_set_parent(libvlc_instance_t, drawable, exception);
120
121         libVlc.libvlc_media_player_play(mediaInstance, exception);
122     }
123 }