]> git.sesse.net Git - vlc/blob - bindings/java/samples/client/src/main/java/VlcClient.java
jvlc: errorOccurred callback added
[vlc] / bindings / java / samples / client / src / main / java / VlcClient.java
1 /*****************************************************************************
2  * VlcClient.java: Sample Swing player
3  *****************************************************************************
4  * Copyright (C) 1998-2006 the VideoLAN team
5  * 
6  * Created on 28-feb-2006
7  *
8  * $Id: $
9  *
10  * This program is free software; you can redistribute it
11  * and/or modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2 of the
13  * License, or (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * General Public License for more details.
19  * 
20  * You should have received a copy of the GNU General Public
21  * License along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
23  * 
24  */
25
26 import java.awt.Canvas;
27 import java.awt.Frame;
28 import java.awt.event.WindowAdapter;
29 import java.awt.event.WindowEvent;
30
31 import javax.swing.JPanel;
32
33 import org.videolan.jvlc.JVLC;
34 import org.videolan.jvlc.Playlist;
35 import org.videolan.jvlc.VLCException;
36
37
38 class VLCPlayerFrame extends Frame
39 {
40
41     private Playlist playlist;
42
43     public Canvas jvcanvas;
44
45     public VLCPlayerFrame()
46     {
47         initComponents();
48     }
49
50     private void initComponents()
51     {
52
53         java.awt.GridBagConstraints gridBagConstraints;
54
55         fullScreenButton = new javax.swing.JButton();
56         jTextField1 = new javax.swing.JTextField();
57         setButton = new javax.swing.JButton();
58         pauseButton = new javax.swing.JButton();
59         stopButton = new javax.swing.JButton();
60
61         jvcc = new JPanel();
62         jvcanvas = new java.awt.Canvas();
63         jvcanvas.setSize(200, 200);
64         jvcc.add(jvcanvas);
65         
66         jvlc = new JVLC();
67         
68         playlist = new Playlist(jvlc);
69
70         setLayout(new java.awt.GridBagLayout());
71
72         gridBagConstraints = new java.awt.GridBagConstraints();
73         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.CENTER;
74         gridBagConstraints.gridx = 0;
75         gridBagConstraints.gridy = 0;
76         add(jvcc, gridBagConstraints);
77
78         fullScreenButton.setText("FullScreen");
79         fullScreenButton.addActionListener(new java.awt.event.ActionListener()
80         {
81
82             public void actionPerformed(java.awt.event.ActionEvent evt)
83             {
84                 fullScreenButtonActionPerformed(evt);
85             }
86         });
87
88         gridBagConstraints = new java.awt.GridBagConstraints();
89         gridBagConstraints.gridx = 0;
90         gridBagConstraints.gridy = 2;
91         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
92         add(fullScreenButton, gridBagConstraints);
93
94         jTextField1.setText("file://a.avi");
95         gridBagConstraints = new java.awt.GridBagConstraints();
96         gridBagConstraints.gridx = 0;
97         gridBagConstraints.gridy = 1;
98         gridBagConstraints.gridwidth = 2;
99         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
100         add(jTextField1, gridBagConstraints);
101
102         setButton.setText("Set item");
103         setButton.addActionListener(new java.awt.event.ActionListener()
104         {
105
106             public void actionPerformed(java.awt.event.ActionEvent evt)
107             {
108                 setButtonActionPerformed(evt);
109             }
110         });
111         gridBagConstraints = new java.awt.GridBagConstraints();
112         gridBagConstraints.gridx = 2;
113         gridBagConstraints.gridy = 1;
114         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
115         add(setButton, gridBagConstraints);
116
117         pauseButton.setText("Play/Pause");
118         pauseButton.addActionListener(new java.awt.event.ActionListener()
119         {
120
121             public void actionPerformed(java.awt.event.ActionEvent evt)
122             {
123                 pauseButtonActionPerformed(evt);
124             }
125         });
126         gridBagConstraints = new java.awt.GridBagConstraints();
127         gridBagConstraints.gridx = 1;
128         gridBagConstraints.gridy = 2;
129         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
130         add(pauseButton, gridBagConstraints);
131
132         stopButton.setText("Stop");
133         stopButton.addActionListener(new java.awt.event.ActionListener()
134         {
135
136             public void actionPerformed(java.awt.event.ActionEvent evt)
137             {
138                 stopButtonActionPerformed(evt);
139             }
140         });
141         gridBagConstraints = new java.awt.GridBagConstraints();
142         gridBagConstraints.gridx = 2;
143         gridBagConstraints.gridy = 2;
144         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
145         add(stopButton, gridBagConstraints);
146
147         pack();
148
149     }
150
151     private void stopButtonActionPerformed(java.awt.event.ActionEvent evt)
152     {
153         try
154         {
155             playlist.stop();
156         }
157         catch (Exception e)
158         {
159             e.printStackTrace();
160         }
161     }
162
163     private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt)
164     {
165         try
166         {
167             playlist.togglePause();
168         }
169         catch (Exception e)
170         {
171             e.printStackTrace();
172         }
173     }
174
175     private void setButtonActionPerformed(java.awt.event.ActionEvent evt)
176     {
177         try
178         {
179             jvlc.setVideoOutput(jvcanvas);
180             playlist.add(jTextField1.getText(), "a.avi");
181             playlist.play();
182         }
183         catch (VLCException e)
184         {
185             // TODO Auto-generated catch block
186             e.printStackTrace();
187         }
188     }
189
190     private void fullScreenButtonActionPerformed(java.awt.event.ActionEvent evt)
191     {
192         // jvlc.fullScreen();
193     }
194
195     private javax.swing.JButton setButton;
196
197     private javax.swing.JButton pauseButton;
198
199     private javax.swing.JButton stopButton;
200
201     private javax.swing.JButton fullScreenButton;
202
203     private javax.swing.JTextField jTextField1;
204
205     private JPanel jvcc;
206
207     public JVLC jvlc;
208     // MediaControlInstance mci;
209
210 }
211
212
213 public class VlcClient
214 {
215
216     public static void main(String[] args)
217     {
218         Frame f = new VLCPlayerFrame();
219         f.setBounds(0, 0, 500, 500);
220         f.addWindowListener(new WindowAdapter()
221         {
222
223             @Override
224             public void windowClosing(WindowEvent ev)
225             {
226                 System.exit(0);
227             }
228         });
229         f.setVisible(true);
230     }
231 }