]> git.sesse.net Git - vlc/blob - bindings/java/samples/client/src/main/java/VlcClient.java
Add some locking.
[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.MediaPlayer;
35
36
37 class VLCPlayerFrame extends Frame
38 {
39
40     /**
41      * 
42      */
43     private static final long serialVersionUID = -7471950211795850421L;
44
45     public Canvas jvcanvas;
46
47     private MediaPlayer mediaPlayer;
48
49     public VLCPlayerFrame(String[] args)
50     {
51         initComponents(args);
52     }
53
54     private void initComponents(String[] args)
55     {
56
57         java.awt.GridBagConstraints gridBagConstraints;
58
59         fullScreenButton = new javax.swing.JButton();
60         jTextField1 = new javax.swing.JTextField();
61         setButton = new javax.swing.JButton();
62         pauseButton = new javax.swing.JButton();
63         stopButton = new javax.swing.JButton();
64
65         jvcc = new JPanel();
66         jvcanvas = new java.awt.Canvas();
67         jvcanvas.setSize(200, 200);
68         jvcc.add(jvcanvas);
69
70         jvlc = new JVLC(args);
71         jvlc.setVideoOutput(jvcanvas);
72         
73         setLayout(new java.awt.GridBagLayout());
74
75         gridBagConstraints = new java.awt.GridBagConstraints();
76         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.CENTER;
77         gridBagConstraints.gridx = 0;
78         gridBagConstraints.gridy = 0;
79         add(jvcc, gridBagConstraints);
80
81         fullScreenButton.setText("FullScreen");
82         fullScreenButton.addActionListener(new java.awt.event.ActionListener()
83         {
84
85             public void actionPerformed(java.awt.event.ActionEvent evt)
86             {
87                 fullScreenButtonActionPerformed(evt);
88             }
89         });
90
91         gridBagConstraints = new java.awt.GridBagConstraints();
92         gridBagConstraints.gridx = 0;
93         gridBagConstraints.gridy = 2;
94         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
95         add(fullScreenButton, gridBagConstraints);
96
97         jTextField1.setText("file://a.avi");
98         gridBagConstraints = new java.awt.GridBagConstraints();
99         gridBagConstraints.gridx = 0;
100         gridBagConstraints.gridy = 1;
101         gridBagConstraints.gridwidth = 2;
102         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
103         add(jTextField1, gridBagConstraints);
104
105         setButton.setText("Set item");
106         setButton.addActionListener(new java.awt.event.ActionListener()
107         {
108
109             public void actionPerformed(java.awt.event.ActionEvent evt)
110             {
111                 setButtonActionPerformed(evt);
112             }
113         });
114         gridBagConstraints = new java.awt.GridBagConstraints();
115         gridBagConstraints.gridx = 2;
116         gridBagConstraints.gridy = 1;
117         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
118         add(setButton, gridBagConstraints);
119
120         pauseButton.setText("Play/Pause");
121         pauseButton.addActionListener(new java.awt.event.ActionListener()
122         {
123
124             public void actionPerformed(java.awt.event.ActionEvent evt)
125             {
126                 pauseButtonActionPerformed(evt);
127             }
128         });
129         gridBagConstraints = new java.awt.GridBagConstraints();
130         gridBagConstraints.gridx = 1;
131         gridBagConstraints.gridy = 2;
132         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
133         add(pauseButton, gridBagConstraints);
134
135         stopButton.setText("Stop");
136         stopButton.addActionListener(new java.awt.event.ActionListener()
137         {
138
139             public void actionPerformed(java.awt.event.ActionEvent evt)
140             {
141                 stopButtonActionPerformed(evt);
142             }
143         });
144         gridBagConstraints = new java.awt.GridBagConstraints();
145         gridBagConstraints.gridx = 2;
146         gridBagConstraints.gridy = 2;
147         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
148         add(stopButton, gridBagConstraints);
149
150         pack();
151
152     }
153
154     private void stopButtonActionPerformed(java.awt.event.ActionEvent evt)
155     {
156         if (mediaPlayer == null)
157         {
158             return;
159         }
160         mediaPlayer.stop();
161     }
162
163     private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt)
164     {
165         if (mediaPlayer == null)
166         {
167             return;
168         }
169         mediaPlayer.pause();
170     }
171
172     private void setButtonActionPerformed(java.awt.event.ActionEvent evt)
173     {
174         if (mediaPlayer != null)
175         {
176             mediaPlayer.stop();
177             mediaPlayer.release();
178             jvcanvas = new java.awt.Canvas();
179         }
180         mediaPlayer = jvlc.play(jTextField1.getText());
181     }
182
183     private void fullScreenButtonActionPerformed(java.awt.event.ActionEvent evt)
184     {
185         // jvlc.fullScreen();
186     }
187
188     private javax.swing.JButton setButton;
189
190     private javax.swing.JButton pauseButton;
191
192     private javax.swing.JButton stopButton;
193
194     private javax.swing.JButton fullScreenButton;
195
196     private javax.swing.JTextField jTextField1;
197
198     private JPanel jvcc;
199
200     public JVLC jvlc;
201     // MediaControlInstance mci;
202
203 }
204
205
206 public class VlcClient
207 {
208
209     public static void main(String[] args)
210     {
211         Frame f = new VLCPlayerFrame(args);
212         f.setBounds(0, 0, 500, 500);
213         f.addWindowListener(new WindowAdapter()
214         {
215
216             @Override
217             public void windowClosing(WindowEvent ev)
218             {
219                 System.exit(0);
220             }
221         });
222         f.setVisible(true);
223     }
224 }