libvlc events related functions renamed
[vlc/bindings/jvlc.git] / 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: AudioIntf.java 8 2006-02-28 12:03:47Z little $
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.Frame;
27 import java.awt.event.WindowAdapter;
28 import java.awt.event.WindowEvent;
29
30 import org.videolan.jvlc.JVLCPanel;
31 import org.videolan.jvlc.JVLC;
32 import org.videolan.jvlc.VLCException;
33
34 class VLCPlayerFrame  extends Frame {
35     public VLCPlayerFrame() {
36         initComponents();
37     }
38     
39     private void initComponents() {
40
41         java.awt.GridBagConstraints gridBagConstraints; 
42
43         fullScreenButton    = new javax.swing.JButton();
44         jTextField1         = new javax.swing.JTextField();
45         setButton           = new javax.swing.JButton();
46         pauseButton         = new javax.swing.JButton();
47         stopButton          = new javax.swing.JButton();
48
49         jvcc   = new JVLCPanel();
50         jvlc = jvcc.getJVLCObject();
51
52         setLayout(new java.awt.GridBagLayout());
53
54         gridBagConstraints = new java.awt.GridBagConstraints();
55         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.CENTER;
56         gridBagConstraints.gridx = 0;
57         gridBagConstraints.gridy = 0;
58         add( jvcc , gridBagConstraints);
59         
60         fullScreenButton.setText("FullScreen");
61         fullScreenButton.addActionListener(new java.awt.event.ActionListener() {
62             public void actionPerformed(java.awt.event.ActionEvent evt) {
63                 fullScreenButtonActionPerformed(evt);
64             }
65         });
66
67         gridBagConstraints = new java.awt.GridBagConstraints();
68         gridBagConstraints.gridx = 0;
69         gridBagConstraints.gridy = 2;
70         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
71         add( fullScreenButton, gridBagConstraints);
72
73
74         jTextField1.setText("file://a.avi");
75         gridBagConstraints = new java.awt.GridBagConstraints();
76         gridBagConstraints.gridx = 0;
77         gridBagConstraints.gridy = 1;
78         gridBagConstraints.gridwidth = 2;
79         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
80         add(jTextField1, gridBagConstraints);
81
82
83         setButton.setText("Set item");
84         setButton.addActionListener(new java.awt.event.ActionListener() {
85             public void actionPerformed(java.awt.event.ActionEvent evt) {
86                 setButtonActionPerformed(evt);
87             }
88         });
89         gridBagConstraints = new java.awt.GridBagConstraints();
90         gridBagConstraints.gridx = 2;
91         gridBagConstraints.gridy = 1;
92         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
93         add(setButton, gridBagConstraints);
94
95
96         pauseButton.setText("Play/Pause");
97         pauseButton.addActionListener(new java.awt.event.ActionListener() {
98             public void actionPerformed(java.awt.event.ActionEvent evt) {
99                 pauseButtonActionPerformed(evt);
100             }
101         });
102         gridBagConstraints = new java.awt.GridBagConstraints();
103         gridBagConstraints.gridx = 1;
104         gridBagConstraints.gridy = 2;
105         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
106         add(pauseButton, gridBagConstraints);
107
108         stopButton.setText("Stop");
109         stopButton.addActionListener(new java.awt.event.ActionListener() {
110             public void actionPerformed(java.awt.event.ActionEvent evt) {
111                 stopButtonActionPerformed(evt);
112             }
113         });
114         gridBagConstraints = new java.awt.GridBagConstraints();
115         gridBagConstraints.gridx = 2;
116         gridBagConstraints.gridy = 2;
117         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
118         add(stopButton, gridBagConstraints);
119       
120         pack();
121        
122         
123         
124     }
125
126     private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {
127         try {
128             //mci.stop(new Position(10000, PositionOrigin.ABSOLUTE, PositionKey.MEDIATIME));
129             jvlc.playlist.stop();
130         } catch (Exception e) {
131             e.printStackTrace();
132         }
133     }
134
135     private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt) {
136         try {
137             //System.out.println(mci.getMediaPosition(PositionOrigin.ABSOLUTE, PositionKey.BYTECOUNT));
138             jvlc.playlist.togglePause();
139         } catch (Exception e) {
140             e.printStackTrace();
141         }
142     }
143
144     private void setButtonActionPerformed(java.awt.event.ActionEvent evt) {
145         try {
146                         jvlc.playlist.add("file://a.avi", "a.avi");
147                         jvlc.playlist.play(-1, null);
148                 } catch (VLCException e) {
149                         // TODO Auto-generated catch block
150                         e.printStackTrace();
151                 }
152     }
153
154     private void fullScreenButtonActionPerformed(java.awt.event.ActionEvent evt) {
155         //jvlc.fullScreen();
156     }
157     
158     private javax.swing.JButton setButton;
159     private javax.swing.JButton pauseButton;
160     private javax.swing.JButton stopButton;
161     private javax.swing.JButton fullScreenButton;
162     private javax.swing.JTextField jTextField1;
163     private JVLCPanel jvcc;
164     public JVLC jvlc;
165     //MediaControlInstance mci;
166     
167 }
168
169
170 public class VlcClient {
171
172     public static void main(String[] args) {
173         Frame f = new  VLCPlayerFrame();
174         f.setBounds(0, 0, 500, 500);
175         f.addWindowListener( new WindowAdapter() {
176                 public void windowClosing(WindowEvent ev) {
177                     System.exit(0);
178                 }
179             } );
180         f.setVisible(true);
181     }
182 }