1 /*****************************************************************************
2 * VlcClient.java: Sample Swing player
3 *****************************************************************************
4 * Copyright (C) 1998-2006 the VideoLAN team
6 * Created on 28-feb-2006
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.
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.
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.
26 import java.awt.Canvas;
27 import java.awt.Frame;
28 import java.awt.event.WindowAdapter;
29 import java.awt.event.WindowEvent;
31 import javax.swing.JPanel;
33 import org.videolan.jvlc.JVLC;
34 import org.videolan.jvlc.MediaPlayer;
37 class VLCPlayerFrame extends Frame
43 private static final long serialVersionUID = -7471950211795850421L;
45 public Canvas jvcanvas;
47 private MediaPlayer mediaPlayer;
49 public VLCPlayerFrame(String[] args)
54 private void initComponents(String[] args)
57 java.awt.GridBagConstraints gridBagConstraints;
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();
66 jvcanvas = new java.awt.Canvas();
67 jvcanvas.setSize(200, 200);
70 jvlc = new JVLC(args);
71 jvlc.setVideoOutput(jvcanvas);
73 setLayout(new java.awt.GridBagLayout());
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);
81 fullScreenButton.setText("FullScreen");
82 fullScreenButton.addActionListener(new java.awt.event.ActionListener()
85 public void actionPerformed(java.awt.event.ActionEvent evt)
87 fullScreenButtonActionPerformed(evt);
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);
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);
105 setButton.setText("Set item");
106 setButton.addActionListener(new java.awt.event.ActionListener()
109 public void actionPerformed(java.awt.event.ActionEvent evt)
111 setButtonActionPerformed(evt);
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);
120 pauseButton.setText("Play/Pause");
121 pauseButton.addActionListener(new java.awt.event.ActionListener()
124 public void actionPerformed(java.awt.event.ActionEvent evt)
126 pauseButtonActionPerformed(evt);
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);
135 stopButton.setText("Stop");
136 stopButton.addActionListener(new java.awt.event.ActionListener()
139 public void actionPerformed(java.awt.event.ActionEvent evt)
141 stopButtonActionPerformed(evt);
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);
154 private void stopButtonActionPerformed(java.awt.event.ActionEvent evt)
156 if (mediaPlayer == null)
163 private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt)
165 if (mediaPlayer == null)
172 private void setButtonActionPerformed(java.awt.event.ActionEvent evt)
174 if (mediaPlayer != null)
177 mediaPlayer.release();
178 jvcanvas = new java.awt.Canvas();
180 mediaPlayer = jvlc.play(jTextField1.getText());
183 private void fullScreenButtonActionPerformed(java.awt.event.ActionEvent evt)
185 // jvlc.fullScreen();
188 private javax.swing.JButton setButton;
190 private javax.swing.JButton pauseButton;
192 private javax.swing.JButton stopButton;
194 private javax.swing.JButton fullScreenButton;
196 private javax.swing.JTextField jTextField1;
201 // MediaControlInstance mci;
206 public class VlcClient
209 public static void main(String[] args)
211 Frame f = new VLCPlayerFrame(args);
212 f.setBounds(0, 0, 500, 500);
213 f.addWindowListener(new WindowAdapter()
217 public void windowClosing(WindowEvent ev)