-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
173 lines (132 loc) · 5.07 KB
/
Client.java
File metadata and controls
173 lines (132 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import java.io.*;
import java.net.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.SwingUtilities;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
import uk.co.caprica.vlcj.mrl.RtpMrl;
public class Client{
SIPclient sip;
private final JFrame frame;
private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
public static void main(final String[] args) {
new NativeDiscovery().discover();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Client(args);
}
});
}
final static int READY = 1;
public Client(String[] args) {
frame = new JFrame("Media Player");
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension screenSize = tk.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
int state;
//SIP PORT: 5804
//RTSP PORT: 5854
if(args.length != 3) {
System.out.println("./Client [Local IP] [SIP port] [URI SIP]");
System.exit(1);
}
int port_sip = Integer.parseInt(args[1]);
int rtsp_port = 0;
String movie = "";
try{
sip = new SIPclient (args[0], port_sip);
sip.initiateSession(args[2]);
rtsp_port = sip.getRtspPort();
movie = sip.getRtspURI();
}catch(Exception e){
}
System.out.println("MOVIE: " + movie);
System.out.println("PORT: " + rtsp_port);
RTSP rtsp = new RTSP("monitor02.lab.it.uc3m.es", rtsp_port, 5804, "movie.mp4");
frame.setSize(screenWidth / 2, screenHeight / 2);
frame.setLocation(screenWidth / 3, screenHeight / 3);
//TO DO! choose the correct arguments for the methods below. Add more method calls as necessary
String mrl = new RtpMrl().multicastAddress("239.0.0.189")
.port(5804)
.value();
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
mediaPlayerComponent.release();
System.exit(0);
}
});
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
contentPane.add(mediaPlayerComponent, BorderLayout.CENTER);
JPanel controlsPane = new JPanel();
JButton setupButton = new JButton("Setup");
controlsPane.add(setupButton);
contentPane.add(controlsPane, BorderLayout.SOUTH);
//Handler for SETUP button
//-----------------------
setupButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
rtsp.send_request("SETUP");
}
});
//Definition of PLAY button
//----------------------
JButton playButton = new JButton("Play");
controlsPane.add(playButton);
contentPane.add(controlsPane, BorderLayout.SOUTH);
//Handler for PLAY button
//-----------------------
playButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
rtsp.send_request("PLAY");
// if(state == READY)
mediaPlayerComponent.getMediaPlayer().playMedia(mrl);
}
});
//TO DO! implement a PAUSE button to pause video playback.
//...
JButton pauseButton = new JButton("Pause");
controlsPane.add(pauseButton);
contentPane.add(controlsPane, BorderLayout.SOUTH);
//Handler for PLAY button
//-----------------------
pauseButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//TO DO!! configure the playback of the video received via RTP, or resume a paused playback.
//...
rtsp.send_request("PAUSE");
}
});
JButton tearButton = new JButton("Stop");
controlsPane.add(tearButton);
contentPane.add(controlsPane, BorderLayout.SOUTH);
//Handler for PLAY button
//-----------------------
tearButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//TO DO!! configure the playback of the video received via RTP, or resume a paused playback.
//...
rtsp.send_request("TEARDOWN");
try{
sip.terminateSession();
}catch(Exception otro_e){
}
}
});
//Makes visible the window
frame.setContentPane(contentPane);
frame.setVisible(true);
}
}