Révision 3192
tmp/org.txm.backtomedia.rcp/plugin.xml (revision 3192) | ||
---|---|---|
125 | 125 |
<extension |
126 | 126 |
point="org.eclipse.ui.editors"> |
127 | 127 |
<editor |
128 |
class="org.txm.backtomedia.editors.vlcplayer.MediaPlayerEditor"
|
|
128 |
class="org.txm.backtomedia.editors.player.MediaPlayerEditor" |
|
129 | 129 |
default="false" |
130 |
id="org.txm.backtomedia.editors.vlcplayer.MediaPlayerEditor"
|
|
130 |
id="org.txm.backtomedia.editors.player.MediaPlayerEditor" |
|
131 | 131 |
name="%editor.name"> |
132 | 132 |
</editor> |
133 | 133 |
</extension> |
tmp/org.txm.backtomedia.rcp/META-INF/MANIFEST.MF (revision 3192) | ||
---|---|---|
22 | 22 |
Bundle-Vendor: %Bundle-Vendor |
23 | 23 |
Export-Package: org.txm.backtomedia.commands.function, |
24 | 24 |
org.txm.backtomedia.editors.input, |
25 |
org.txm.backtomedia.editors.vlcplayer,
|
|
25 |
org.txm.backtomedia.editors.player, |
|
26 | 26 |
org.txm.backtomedia.preferences, |
27 | 27 |
uk.co.caprica.vlcj.factory.swt, |
28 | 28 |
uk.co.caprica.vlcj.player.embedded.videosurface.swt, |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/BackToMedia.java (revision 3192) | ||
---|---|---|
45 | 45 |
import org.eclipse.ui.IWorkbenchPart; |
46 | 46 |
import org.eclipse.ui.handlers.HandlerUtil; |
47 | 47 |
import org.eclipse.ui.part.EditorPart; |
48 |
import org.txm.backtomedia.editors.vlcplayer.VLCPlayer;
|
|
49 |
import org.txm.backtomedia.editors.vlcplayer.MediaPlayerEditor;
|
|
48 |
import org.txm.backtomedia.editors.player.MediaPlayerEditor;
|
|
49 |
import org.txm.backtomedia.editors.player.VLCPlayer;
|
|
50 | 50 |
import org.txm.backtomedia.preferences.BackToMediaPreferences; |
51 | 51 |
import org.txm.concordance.core.functions.Line; |
52 | 52 |
import org.txm.concordance.rcp.editors.ConcordanceEditor; |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/SimpleFileDialog.java (revision 3192) | ||
---|---|---|
16 | 16 |
public class SimpleFileDialog extends InputDialog { |
17 | 17 |
|
18 | 18 |
Button selectButton; |
19 |
String defaultPath = null; |
|
19 | 20 |
|
20 | 21 |
public SimpleFileDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, IInputValidator validator) { |
21 | 22 |
super(parentShell, dialogTitle, dialogMessage, initialValue, validator); |
... | ... | |
29 | 30 |
layout.numColumns = layout.numColumns + 1; |
30 | 31 |
|
31 | 32 |
getText().setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false, 2, 1)); |
33 |
if (defaultPath != null) { |
|
34 |
getText().setText(defaultPath); |
|
35 |
} |
|
32 | 36 |
setErrorMessage(null); |
33 | 37 |
selectButton = new Button(p, SWT.PUSH); |
34 | 38 |
selectButton.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true)); |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/OpenMediaPlayer.java (revision 3192) | ||
---|---|---|
50 | 50 |
import org.eclipse.ui.PartInitException; |
51 | 51 |
import org.eclipse.ui.handlers.HandlerUtil; |
52 | 52 |
import org.txm.backtomedia.editors.input.MediaPlayerEditorInput; |
53 |
import org.txm.backtomedia.editors.vlcplayer.MediaPlayerEditor; |
|
53 |
import org.txm.backtomedia.editors.player.MediaPlayerEditor; |
|
54 |
import org.txm.backtomedia.preferences.BackToMediaPreferences; |
|
54 | 55 |
import org.txm.rcp.StatusLine; |
55 | 56 |
import org.txm.rcp.TXMWindows; |
56 | 57 |
|
... | ... | |
64 | 65 |
public class OpenMediaPlayer extends AbstractHandler { |
65 | 66 |
|
66 | 67 |
/** The ID. */ |
67 |
public static String ID = "org.txm.rcp.commands.BackToMedia"; //$NON-NLS-1$
|
|
68 |
public static String ID = OpenMediaPlayer.class.getSimpleName(); //$NON-NLS-1$
|
|
68 | 69 |
|
69 | 70 |
/* |
70 | 71 |
* (non-Javadoc) |
... | ... | |
92 | 93 |
} |
93 | 94 |
|
94 | 95 |
Shell sh = HandlerUtil.getActiveShell(event); |
95 |
SimpleFileDialog fd = new SimpleFileDialog(sh, "Opening media file...", "Enter file path or URL", "", null);
|
|
96 |
SimpleFileDialog fd = new SimpleFileDialog(sh, "Opening media file...", "Enter file path or URL", BackToMediaPreferences.getInstance().getString(ID), null);
|
|
96 | 97 |
// FileDialog fd = new FileDialog(new Shell(), SWT.SAVE); |
97 | 98 |
// fd.setText(MessagesMP.select_file); |
98 | 99 |
|
... | ... | |
109 | 110 |
else { |
110 | 111 |
|
111 | 112 |
} |
113 |
BackToMediaPreferences.getInstance().put(ID, mrl); |
|
112 | 114 |
return openEditor(mrl, 0); |
113 | 115 |
} |
114 | 116 |
} |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/preferences/BackToMediaPreferencePage.java (revision 3192) | ||
---|---|---|
156 | 156 |
|
157 | 157 |
updateEnables(BackToMediaPreferences.getInstance().getString(BackToMediaPreferences.SYNCMODE)); |
158 | 158 |
|
159 |
String[][] players = { { "JFX", "JFX" }, { "VLC", "VLC" } }; |
|
159 |
String[][] players = {{ "HTML", "HTML" }, { "JFX", "JFX" }, { "VLC", "VLC" } };
|
|
160 | 160 |
playerProperty = new ComboFieldEditor(BackToMediaPreferences.PLAYER, "Embedded player", players, getFieldEditorParent()); |
161 | 161 |
addField(playerProperty); |
162 | 162 |
} |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/preferences/BackToMediaPreferences.java (revision 3192) | ||
---|---|---|
67 | 67 |
super.initializeDefaultPreferences(); |
68 | 68 |
|
69 | 69 |
Preferences preferences = DefaultScope.INSTANCE.getNode(getPreferencesNodeQualifier()); |
70 |
preferences.put(PLAYER, "JFX");
|
|
70 |
preferences.put(PLAYER, "HTML");
|
|
71 | 71 |
preferences.putBoolean(REPEAT, true); |
72 | 72 |
preferences.put(SYNCMODE, MILESTONEMODE); |
73 | 73 |
preferences.put(STRUCTURE, "u"); |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/editors/player/MediaPlayerComposite.java (revision 3192) | ||
---|---|---|
1 |
package org.txm.backtomedia.editors.player; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
import org.eclipse.swt.SWT; |
|
6 |
import org.eclipse.swt.events.SelectionEvent; |
|
7 |
import org.eclipse.swt.events.SelectionListener; |
|
8 |
import org.eclipse.swt.layout.GridData; |
|
9 |
import org.eclipse.swt.widgets.Button; |
|
10 |
import org.eclipse.swt.widgets.Composite; |
|
11 |
import org.eclipse.swt.widgets.FileDialog; |
|
12 |
import org.eclipse.swt.widgets.Label; |
|
13 |
import org.eclipse.swt.widgets.Scale; |
|
14 |
import org.txm.backtomedia.commands.function.TripleRangeSlider; |
|
15 |
import org.txm.backtomedia.preferences.BackToMediaPreferences; |
|
16 |
import org.txm.utils.logger.Log; |
|
17 |
|
|
18 |
import javafx.util.Duration; |
|
19 |
import vlcplayerrcp.MessagesMP; |
|
20 |
|
|
21 |
public class MediaPlayerComposite extends Composite { |
|
22 |
|
|
23 |
IPlayer player; |
|
24 |
private Scale rateField; |
|
25 |
private Label rateValueLabel; |
|
26 |
private Scale volumeField; |
|
27 |
private Label volumeValueLabel; |
|
28 |
private Button playButton; |
|
29 |
private Button stopButton; |
|
30 |
private Button repeatButton; |
|
31 |
Label timeLabel; |
|
32 |
TripleRangeSlider timeRange; |
|
33 |
|
|
34 |
protected boolean userStopped; |
|
35 |
protected String currentlyPlayed = ""; //$NON-NLS-1$ |
|
36 |
protected int start, end; |
|
37 |
protected boolean hasEnded = false; |
|
38 |
protected String previouslyPlayed = ""; //$NON-NLS-1$ |
|
39 |
protected boolean repeat = false; |
|
40 |
protected int volume = 100; |
|
41 |
protected int time; |
|
42 |
private int mins; |
|
43 |
private int secs; |
|
44 |
|
|
45 |
public MediaPlayerComposite(Composite parent, int style) { |
|
46 |
|
|
47 |
super(parent, style); |
|
48 |
|
|
49 |
if ("HTML".equals(BackToMediaPreferences.getInstance().getString(BackToMediaPreferences.PLAYER))) { |
|
50 |
player = new HTMLPlayer(parent, SWT.NONE); |
|
51 |
} else if ("JFX".equals(BackToMediaPreferences.getInstance().getString(BackToMediaPreferences.PLAYER))) { |
|
52 |
player = new JFXPlayer(parent, SWT.NONE); |
|
53 |
} |
|
54 |
else if ("VLC".equals(BackToMediaPreferences.getInstance().getString(BackToMediaPreferences.PLAYER))) { |
|
55 |
player = new VLCPlayer(parent, SWT.NONE); |
|
56 |
} |
|
57 |
else { |
|
58 |
player = new HTMLPlayer(parent, SWT.NONE); |
|
59 |
} |
|
60 |
|
|
61 |
|
|
62 |
// THE CONTROL BUTTONS |
|
63 |
playButton = new Button(this, SWT.PUSH); |
|
64 |
GridData playLayoutData = new GridData(SWT.FILL, SWT.CENTER, false, false); |
|
65 |
playButton.setLayoutData(playLayoutData); |
|
66 |
playButton.setText(MessagesMP.play); |
|
67 |
playButton.addSelectionListener(new SelectionListener() { |
|
68 |
|
|
69 |
@Override |
|
70 |
public void widgetSelected(SelectionEvent e) { |
|
71 |
userStopped = false; |
|
72 |
if (currentlyPlayed.length() == 0) { |
|
73 |
selectMedia(); |
|
74 |
playButton.setText(MessagesMP.pause); |
|
75 |
playButton.getParent().layout(); |
|
76 |
} |
|
77 |
else if (player != null && player.isPlaying()) { |
|
78 |
player.pause(); |
|
79 |
} |
|
80 |
else if (player != null && hasEnded) { |
|
81 |
if (player == null) return; |
|
82 |
player.replay(); |
|
83 |
} |
|
84 |
else { |
|
85 |
player.resume(); |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
91 |
}); |
|
92 |
|
|
93 |
// Button browseButton = new Button(this,SWT.PUSH); |
|
94 |
// browseButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); |
|
95 |
// browseButton.setText("Open..."); |
|
96 |
// browseButton.addSelectionListener(new SelectionListener() { |
|
97 |
// @Override |
|
98 |
// public void widgetSelected(SelectionEvent e) { |
|
99 |
// selectMedia(); |
|
100 |
// } |
|
101 |
// |
|
102 |
// @Override |
|
103 |
// public void widgetDefaultSelected(SelectionEvent e) {} |
|
104 |
// }); |
|
105 |
|
|
106 |
stopButton = new Button(this, SWT.PUSH); |
|
107 |
stopButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); |
|
108 |
stopButton.setText(MessagesMP.stop); |
|
109 |
stopButton.addSelectionListener(new SelectionListener() { |
|
110 |
|
|
111 |
@Override |
|
112 |
public void widgetSelected(SelectionEvent e) { |
|
113 |
if (player != null) { |
|
114 |
userStopped = true; |
|
115 |
player.stop(); |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
121 |
}); |
|
122 |
|
|
123 |
timeLabel = new Label(this, SWT.NONE); |
|
124 |
timeLabel.setText("00:00"); //$NON-NLS-1$ |
|
125 |
|
|
126 |
timeRange = new TripleRangeSlider(this, SWT.None); |
|
127 |
timeRange.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
|
128 |
timeRange.setToolTipText(MessagesMP.time_range); |
|
129 |
timeRange.addSelectionListener(new SelectionListener() { |
|
130 |
|
|
131 |
@Override |
|
132 |
public void widgetSelected(SelectionEvent e) { |
|
133 |
TripleRangeSlider.SELECTED_KNOB sk = timeRange.getLastSelectedKnob(); |
|
134 |
switch (sk) { |
|
135 |
case UPPER: |
|
136 |
end = timeRange.getUpperValue(); |
|
137 |
|
|
138 |
player.setStopTime(end); //Duration.seconds(end)); |
|
139 |
if (end < time) { |
|
140 |
// System.out.println("Upper changed: fix time"); |
|
141 |
time = end; |
|
142 |
player.seek(time);//Duration.seconds(time)); |
|
143 |
} |
|
144 |
break; |
|
145 |
case LOWER: |
|
146 |
start = timeRange.getLowerValue(); |
|
147 |
player.setStartTime(start);//Duration.seconds(start)); |
|
148 |
if (start > time) { |
|
149 |
// System.out.println("Lower changed: fix time"); |
|
150 |
time = start; |
|
151 |
player.seek(time);//Duration.seconds(time)); |
|
152 |
} |
|
153 |
break; |
|
154 |
case MIDDLE: |
|
155 |
|
|
156 |
time = timeRange.getMiddleValue(); |
|
157 |
// System.out.println("Middle changed: fix time: " + time); |
|
158 |
|
|
159 |
player.seek(time);//Duration.seconds(time)); |
|
160 |
|
|
161 |
break; |
|
162 |
default: |
|
163 |
// nothing |
|
164 |
} |
|
165 |
// System.out.println("time range: "+start+" -> "+end+" time="+time); |
|
166 |
} |
|
167 |
|
|
168 |
@Override |
|
169 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
170 |
}); |
|
171 |
|
|
172 |
repeatButton = new Button(this, SWT.CHECK); |
|
173 |
repeatButton.setText(MessagesMP.repeat); |
|
174 |
repeat = BackToMediaPreferences.getInstance().getBoolean(BackToMediaPreferences.REPEAT); |
|
175 |
repeatButton.setSelection(repeat); |
|
176 |
repeatButton.addSelectionListener(new SelectionListener() { |
|
177 |
|
|
178 |
@Override |
|
179 |
public void widgetSelected(SelectionEvent e) { |
|
180 |
repeat = repeatButton.getSelection(); |
|
181 |
} |
|
182 |
|
|
183 |
@Override |
|
184 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
185 |
}); |
|
186 |
|
|
187 |
Label l = new Label(this, SWT.NONE); |
|
188 |
l.setText(MessagesMP.rate); |
|
189 |
|
|
190 |
rateField = new Scale(this, SWT.BORDER); |
|
191 |
GridData gdata4 = new GridData(SWT.FILL, SWT.CENTER, false, false); |
|
192 |
gdata4.widthHint = 100; |
|
193 |
rateField.setLayoutData(gdata4); |
|
194 |
rateField.setMaximum(140); |
|
195 |
rateField.setMinimum(70); |
|
196 |
rateField.setSelection(100); |
|
197 |
rateField.setPageIncrement(5); |
|
198 |
|
|
199 |
rateField.addSelectionListener(new SelectionListener() { |
|
200 |
|
|
201 |
@Override |
|
202 |
public void widgetSelected(SelectionEvent e) { |
|
203 |
float rate = rateField.getSelection() / 100.0f; |
|
204 |
player.setRate(rate); |
|
205 |
rateValueLabel.setText("" + rateField.getSelection() + "%"); |
|
206 |
} |
|
207 |
|
|
208 |
@Override |
|
209 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
210 |
}); |
|
211 |
|
|
212 |
rateValueLabel = new Label(this, SWT.NONE); |
|
213 |
rateValueLabel.setText("100%");//$NON-NLS-1$ |
|
214 |
|
|
215 |
l = new Label(this, SWT.NONE); |
|
216 |
l.setText(MessagesMP.volume); |
|
217 |
|
|
218 |
volumeField = new Scale(this, SWT.BORDER); |
|
219 |
gdata4 = new GridData(SWT.FILL, SWT.CENTER, false, false); |
|
220 |
gdata4.widthHint = 100; |
|
221 |
volumeField.setLayoutData(gdata4); |
|
222 |
volumeField.setMinimum(0); |
|
223 |
volumeField.setMaximum(100); |
|
224 |
volumeField.setSelection(volume); |
|
225 |
volumeField.setPageIncrement(5); |
|
226 |
volumeField.addSelectionListener(new SelectionListener() { |
|
227 |
|
|
228 |
@Override |
|
229 |
public void widgetSelected(SelectionEvent e) { |
|
230 |
player.setVolume(volumeField.getSelection()); |
|
231 |
volume = volumeField.getSelection(); |
|
232 |
volumeValueLabel.setText("" + volume + "%"); |
|
233 |
} |
|
234 |
|
|
235 |
@Override |
|
236 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
237 |
}); |
|
238 |
|
|
239 |
volumeValueLabel = new Label(this, SWT.NONE); |
|
240 |
volumeValueLabel.setText("100%"); |
|
241 |
|
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
public void hideStopButton() { |
|
246 |
if (this.stopButton != null && !this.stopButton.isDisposed()) { |
|
247 |
this.stopButton.dispose(); |
|
248 |
} |
|
249 |
} |
|
250 |
|
|
251 |
public void resume() { |
|
252 |
if (player != null) { |
|
253 |
//player.play(); |
|
254 |
playButton.setText(MessagesMP.pause); |
|
255 |
playButton.getParent().layout(); |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
259 |
public void pause() { |
|
260 |
if (player != null) { |
|
261 |
player.pause(); |
|
262 |
playButton.setText(MessagesMP.resume); |
|
263 |
playButton.getParent().layout(); |
|
264 |
} |
|
265 |
} |
|
266 |
|
|
267 |
private void updateTimeLabel() { |
|
268 |
mins = time / 60; |
|
269 |
secs = (time) % 60; |
|
270 |
timeLabel.setText(String.format("%02d:%02d", mins, secs)); //$NON-NLS-1$ |
|
271 |
timeLabel.update(); |
|
272 |
} |
|
273 |
|
|
274 |
public void replay() { |
|
275 |
if (currentlyPlayed.length() > 0) { |
|
276 |
//player.seek(Duration.seconds(start)); |
|
277 |
playButton.setText(MessagesMP.pause); |
|
278 |
playButton.getParent().layout(); |
|
279 |
} |
|
280 |
} |
|
281 |
|
|
282 |
protected void selectMedia() { |
|
283 |
Log.fine(MessagesMP.select_file); |
|
284 |
|
|
285 |
FileDialog fd = new FileDialog(MediaPlayerComposite.this.getShell(), SWT.OPEN); |
|
286 |
fd.setText(MessagesMP.select_file_title); |
|
287 |
File f = new File(previouslyPlayed); |
|
288 |
if (f.isDirectory()) fd.setFilterPath(f.getPath()); |
|
289 |
else fd.setFilterPath(f.getParent()); |
|
290 |
|
|
291 |
String[] filterExt = { "*.*", "*.mp3", "*.mp4", "*.avi", "*.ogg", "*.ogv" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
292 |
fd.setFilterExtensions(filterExt); |
|
293 |
String selected = fd.open(); |
|
294 |
if (selected == null) { |
|
295 |
System.out.println(MessagesMP.cancel); |
|
296 |
return; |
|
297 |
} |
|
298 |
|
|
299 |
currentlyPlayed = selected; |
|
300 |
previouslyPlayed = selected; |
|
301 |
Log.fine(MessagesMP.opening + currentlyPlayed); |
|
302 |
player.play(new File(currentlyPlayed).toURI().toString(), 0, 0); |
|
303 |
} |
|
304 |
|
|
305 |
} |
|
0 | 306 |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/editors/player/HTMLPlayer.java (revision 3192) | ||
---|---|---|
1 |
package org.txm.backtomedia.editors.player; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.time.LocalTime; |
|
5 |
import java.time.format.DateTimeFormatter; |
|
6 |
|
|
7 |
import org.eclipse.swt.SWT; |
|
8 |
import org.eclipse.swt.browser.Browser; |
|
9 |
import org.eclipse.swt.events.SelectionEvent; |
|
10 |
import org.eclipse.swt.events.SelectionListener; |
|
11 |
import org.eclipse.swt.layout.GridData; |
|
12 |
import org.eclipse.swt.layout.GridLayout; |
|
13 |
import org.eclipse.swt.widgets.Button; |
|
14 |
import org.eclipse.swt.widgets.Composite; |
|
15 |
import org.eclipse.swt.widgets.Scale; |
|
16 |
import org.eclipse.swt.widgets.Spinner; |
|
17 |
import org.txm.backtomedia.commands.function.OpenMediaPlayer; |
|
18 |
import org.txm.backtomedia.commands.function.SimpleFileDialog; |
|
19 |
import org.txm.backtomedia.preferences.BackToMediaPreferences; |
|
20 |
import org.txm.rcp.swt.GLComposite; |
|
21 |
|
|
22 |
public class HTMLPlayer extends Composite implements IPlayer { |
|
23 |
|
|
24 |
Browser browser; |
|
25 |
String mrl = null; |
|
26 |
private String login; |
|
27 |
private String mdp; |
|
28 |
private Button stopButton; |
|
29 |
|
|
30 |
public HTMLPlayer(Composite parent, int style) { |
|
31 |
|
|
32 |
super(parent, style); |
|
33 |
parent.setLayout(new GridLayout(1, true)); |
|
34 |
|
|
35 |
GLComposite controls = new GLComposite(parent, SWT.BORDER, "controls"); |
|
36 |
controls.getLayout().numColumns = 20; |
|
37 |
|
|
38 |
Button openButton = new Button(controls, SWT.PUSH); |
|
39 |
openButton.setText("Open..."); |
|
40 |
openButton.addSelectionListener(new SelectionListener() { |
|
41 |
|
|
42 |
@Override |
|
43 |
public void widgetSelected(SelectionEvent event) { |
|
44 |
|
|
45 |
SimpleFileDialog fd = new SimpleFileDialog(HTMLPlayer.this.getDisplay().getActiveShell(), "Opening media file...", "Enter file path or URL", BackToMediaPreferences.getInstance().getString(OpenMediaPlayer.ID), null); |
|
46 |
if (fd.open() == SimpleFileDialog.OK) { |
|
47 |
String mrl = fd.getValue(); |
|
48 |
|
|
49 |
if (mrl != null) { |
|
50 |
File f = new File(mrl); |
|
51 |
if (f.exists()) { |
|
52 |
mrl = new File(mrl).toURI().toString(); |
|
53 |
} |
|
54 |
else { |
|
55 |
|
|
56 |
} |
|
57 |
BackToMediaPreferences.getInstance().put(OpenMediaPlayer.ID, mrl); |
|
58 |
play(mrl, 0); |
|
59 |
} |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
65 |
}); |
|
66 |
|
|
67 |
stopButton = new Button(controls, SWT.PUSH); |
|
68 |
stopButton.setText("Stop"); |
|
69 |
stopButton.addSelectionListener(new SelectionListener() { |
|
70 |
|
|
71 |
@Override |
|
72 |
public void widgetSelected(SelectionEvent event) { |
|
73 |
stop(); |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
78 |
}); |
|
79 |
|
|
80 |
Button playpauseButton = new Button(controls, SWT.TOGGLE); |
|
81 |
playpauseButton.setText("Pause"); |
|
82 |
playpauseButton.setSelection(true); |
|
83 |
playpauseButton.addSelectionListener(new SelectionListener() { |
|
84 |
|
|
85 |
@Override |
|
86 |
public void widgetSelected(SelectionEvent event) { |
|
87 |
if (playpauseButton.getSelection()) { |
|
88 |
resume(); |
|
89 |
playpauseButton.setText("Pause"); |
|
90 |
} else { |
|
91 |
pause(); |
|
92 |
playpauseButton.setText("Play"); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
@Override |
|
97 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
98 |
}); |
|
99 |
|
|
100 |
Button replayButton = new Button(controls, SWT.PUSH); |
|
101 |
replayButton.setText("Re-play"); |
|
102 |
replayButton.addSelectionListener(new SelectionListener() { |
|
103 |
|
|
104 |
@Override |
|
105 |
public void widgetSelected(SelectionEvent event) { |
|
106 |
replay(); |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
111 |
}); |
|
112 |
|
|
113 |
Button loopButton = new Button(controls, SWT.TOGGLE); |
|
114 |
loopButton.setText("Loop"); |
|
115 |
loopButton.addSelectionListener(new SelectionListener() { |
|
116 |
|
|
117 |
@Override |
|
118 |
public void widgetSelected(SelectionEvent event) { |
|
119 |
setRepeat(loopButton.getSelection()); |
|
120 |
} |
|
121 |
|
|
122 |
@Override |
|
123 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
124 |
}); |
|
125 |
|
|
126 |
Scale volumneSpinner = new Scale(controls, SWT.NONE); |
|
127 |
volumneSpinner.setMinimum(0); |
|
128 |
volumneSpinner.setMaximum(100); |
|
129 |
volumneSpinner.setSelection(100); |
|
130 |
volumneSpinner.addSelectionListener(new SelectionListener() { |
|
131 |
|
|
132 |
@Override |
|
133 |
public void widgetSelected(SelectionEvent e) { |
|
134 |
setVolume(volumneSpinner.getSelection()); |
|
135 |
} |
|
136 |
|
|
137 |
@Override |
|
138 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
139 |
}); |
|
140 |
|
|
141 |
Scale rateSpinner = new Scale(controls, SWT.NONE); |
|
142 |
rateSpinner.setMinimum(10); |
|
143 |
rateSpinner.setMaximum(300); |
|
144 |
rateSpinner.setSelection(100); |
|
145 |
rateSpinner.addSelectionListener(new SelectionListener() { |
|
146 |
|
|
147 |
@Override |
|
148 |
public void widgetSelected(SelectionEvent e) { |
|
149 |
setRate(((float)rateSpinner.getSelection())/100.0f); |
|
150 |
} |
|
151 |
|
|
152 |
@Override |
|
153 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
154 |
}); |
|
155 |
|
|
156 |
browser = new Browser(parent, SWT.NONE); |
|
157 |
browser.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); |
|
158 |
browser.setText("<video id=\"video\" width=\"100%\" height=\"100%\" controls></video>"); |
|
159 |
//browser.setText("<video id=\"video\" width=\"100%\" height=\"100%\" controls><source id=\"source\" src=\"\"></source></video>"); |
|
160 |
} |
|
161 |
|
|
162 |
@Override |
|
163 |
public void setCredentials(String login, String mdp) { |
|
164 |
|
|
165 |
//browser.evaluate(TXMCoreMessages.bind("video.;", login, mdp)); |
|
166 |
this.login = login; |
|
167 |
this.mdp = mdp; |
|
168 |
|
|
169 |
} |
|
170 |
|
|
171 |
|
|
172 |
public void hideStopButton() { |
|
173 |
if (this.stopButton != null && !this.stopButton.isDisposed()) { |
|
174 |
this.stopButton.dispose(); |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
DateTimeFormatter hhmmssFormatter = DateTimeFormatter.ISO_LOCAL_TIME; |
|
179 |
@Override |
|
180 |
public boolean play(String mrl, String startTime, String endTime) { |
|
181 |
|
|
182 |
int start=0, end=0; |
|
183 |
if (startTime.matches("[0-9]+.[0-9]+")) { |
|
184 |
start = (int) (Float.parseFloat(startTime)); |
|
185 |
} |
|
186 |
else if (startTime.matches("[0-9]+:[0-9]+:[0-9]+")) { |
|
187 |
if (startTime.indexOf(":") == 1) { |
|
188 |
startTime = "0" + startTime; |
|
189 |
} |
|
190 |
LocalTime time1 = LocalTime.parse(startTime, hhmmssFormatter); |
|
191 |
start = ((time1.getHour() * 60 * 60) + (time1.getMinute() * 60) + time1.getSecond()); |
|
192 |
} |
|
193 |
|
|
194 |
if (endTime.matches("[0-9]+.[0-9]+")) { |
|
195 |
end = (int) ( Float.parseFloat(endTime)); |
|
196 |
} |
|
197 |
else if (endTime.matches("[0-9]+:[0-9]+:[0-9]+")) { |
|
198 |
if (endTime.indexOf(":") == 1) endTime = "0" + endTime; |
|
199 |
LocalTime time1 = LocalTime.parse(endTime, hhmmssFormatter); |
|
200 |
end = ((time1.getHour() * 60 * 60) + (time1.getMinute() * 60) + time1.getSecond()); |
|
201 |
} |
|
202 |
|
|
203 |
return play(mrl, start, end); |
|
204 |
|
|
205 |
} |
|
206 |
|
|
207 |
@Override |
|
208 |
public boolean play(String mrl, int start, int end) { |
|
209 |
|
|
210 |
browser.evaluate("document;"); |
|
211 |
browser.evaluate("document.getElementById(\"video\");"); |
|
212 |
browser.evaluate("document.getElementById(\"source\");"); |
|
213 |
|
|
214 |
if (login != null && mdp != null) { |
|
215 |
mrl = mrl.replace("{0}", login).replace("{1}", mdp); |
|
216 |
} |
|
217 |
|
|
218 |
String script = "document;\n" |
|
219 |
+ "video = document.getElementById('video');\n"; |
|
220 |
|
|
221 |
if (this.mrl == null || !this.mrl.equals(mrl)) { |
|
222 |
script += "video.setAttribute('src', '"+mrl+"');\n"; |
|
223 |
} |
|
224 |
script += "video.play();\n" + |
|
225 |
"video.currentTime="+start+";\n"; |
|
226 |
//System.out.println("EVAL: "+script); |
|
227 |
browser.evaluate(script); |
|
228 |
|
|
229 |
this.mrl = mrl; |
|
230 |
return true; |
|
231 |
} |
|
232 |
|
|
233 |
@Override |
|
234 |
public boolean play(String mrl, int start) { |
|
235 |
|
|
236 |
return play(mrl, start, -1); |
|
237 |
|
|
238 |
} |
|
239 |
|
|
240 |
@Override |
|
241 |
public void stop() { |
|
242 |
|
|
243 |
if (browser.isDisposed()) return; |
|
244 |
|
|
245 |
browser.evaluate("video.pause();"); |
|
246 |
browser.evaluate("video.setAttribute('src', '');"); |
|
247 |
|
|
248 |
} |
|
249 |
|
|
250 |
@Override |
|
251 |
public boolean isMediaLoaded() { |
|
252 |
|
|
253 |
return mrl != null && mrl.length() > 0; |
|
254 |
|
|
255 |
} |
|
256 |
|
|
257 |
@Override |
|
258 |
public void setRepeat(boolean b) { |
|
259 |
|
|
260 |
browser.evaluate("video.loop="+b+";"); |
|
261 |
|
|
262 |
} |
|
263 |
|
|
264 |
@Override |
|
265 |
public boolean isDisposed() { |
|
266 |
|
|
267 |
return browser.isDisposed(); |
|
268 |
|
|
269 |
} |
|
270 |
|
|
271 |
@Override |
|
272 |
public void seek(float time) { |
|
273 |
|
|
274 |
browser.evaluate("video.currentTime="+time+";"); |
|
275 |
|
|
276 |
} |
|
277 |
|
|
278 |
@Override |
|
279 |
public void pause() { |
|
280 |
|
|
281 |
browser.evaluate("video.pause();"); |
|
282 |
|
|
283 |
} |
|
284 |
|
|
285 |
@Override |
|
286 |
public void replay() { |
|
287 |
|
|
288 |
browser.evaluate("video.currentTime=0;"); |
|
289 |
|
|
290 |
} |
|
291 |
|
|
292 |
@Override |
|
293 |
public void resume() { |
|
294 |
|
|
295 |
browser.evaluate("video.play();"); |
|
296 |
|
|
297 |
} |
|
298 |
|
|
299 |
@Override |
|
300 |
public void setVolume(double volume) { |
|
301 |
|
|
302 |
browser.evaluate("video.volume="+volume/100.0d+";"); |
|
303 |
|
|
304 |
} |
|
305 |
|
|
306 |
@Override |
|
307 |
public void setRate(float rate) { |
|
308 |
|
|
309 |
browser.evaluate("video.playbackRate="+rate+";"); |
|
310 |
|
|
311 |
} |
|
312 |
|
|
313 |
@Override |
|
314 |
public boolean isPlaying() { |
|
315 |
Object o = browser.evaluate("return !video.played;"); |
|
316 |
if (o == null) return false; |
|
317 |
if (o instanceof Boolean) { |
|
318 |
return (Boolean)o; |
|
319 |
} |
|
320 |
return false; |
|
321 |
|
|
322 |
} |
|
323 |
|
|
324 |
@Override |
|
325 |
public void setStartTime(float seconds) { |
|
326 |
|
|
327 |
//browser.evaluate(TXMCoreMessages.bind("alert(''set start time {0}'');", seconds)); |
|
328 |
|
|
329 |
} |
|
330 |
|
|
331 |
@Override |
|
332 |
public void setStopTime(float seconds) { |
|
333 |
|
|
334 |
//browser.evaluate(TXMCoreMessages.bind("alert(''set stop time {0}'');", seconds)); |
|
335 |
|
|
336 |
} |
|
337 |
} |
|
0 | 338 |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/editors/player/VLCPlayer.java (revision 3192) | ||
---|---|---|
1 |
package org.txm.backtomedia.editors.player; |
|
2 |
|
|
3 |
import static uk.co.caprica.vlcj.binding.LibVlc.libvlc_new; |
|
4 |
import static uk.co.caprica.vlcj.binding.LibVlc.libvlc_release; |
|
5 |
|
|
6 |
import java.io.File; |
|
7 |
import java.time.LocalTime; |
|
8 |
import java.time.format.DateTimeFormatter; |
|
9 |
import java.util.concurrent.Semaphore; |
|
10 |
|
|
11 |
import org.eclipse.osgi.util.NLS; |
|
12 |
import org.eclipse.swt.SWT; |
|
13 |
import org.eclipse.swt.events.DisposeEvent; |
|
14 |
import org.eclipse.swt.events.DisposeListener; |
|
15 |
import org.eclipse.swt.events.SelectionEvent; |
|
16 |
import org.eclipse.swt.events.SelectionListener; |
|
17 |
import org.eclipse.swt.layout.GridData; |
|
18 |
import org.eclipse.swt.layout.GridLayout; |
|
19 |
import org.eclipse.swt.widgets.Button; |
|
20 |
import org.eclipse.swt.widgets.Composite; |
|
21 |
import org.eclipse.swt.widgets.FileDialog; |
|
22 |
import org.eclipse.swt.widgets.Label; |
|
23 |
import org.eclipse.swt.widgets.Scale; |
|
24 |
import org.txm.backtomedia.commands.function.TripleRangeSlider; |
|
25 |
import org.txm.backtomedia.preferences.BackToMediaPreferences; |
|
26 |
import org.txm.utils.logger.Log; |
|
27 |
|
|
28 |
import com.sun.jna.StringArray; |
|
29 |
|
|
30 |
import uk.co.caprica.vlcj.binding.internal.libvlc_instance_t; |
|
31 |
import uk.co.caprica.vlcj.factory.discovery.NativeDiscovery; |
|
32 |
import uk.co.caprica.vlcj.factory.discovery.strategy.NativeDiscoveryStrategy; |
|
33 |
import uk.co.caprica.vlcj.factory.swt.SwtMediaPlayerFactory; |
|
34 |
import uk.co.caprica.vlcj.player.base.MediaPlayer; |
|
35 |
import uk.co.caprica.vlcj.player.base.MediaPlayerEventAdapter; |
|
36 |
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent; |
|
37 |
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer; |
|
38 |
import uk.co.caprica.vlcj.player.embedded.videosurface.swt.CompositeVideoSurface; |
|
39 |
import uk.co.caprica.vlcj.support.version.LibVlcVersion; |
|
40 |
import vlcplayerrcp.MessagesMP; |
|
41 |
|
|
42 |
public class VLCPlayer extends Composite implements IPlayer { |
|
43 |
|
|
44 |
static { // force native libs discovery -> fix Mac OS X init |
|
45 |
NativeDiscovery discovery = new NativeDiscovery() { |
|
46 |
|
|
47 |
@Override |
|
48 |
protected void onFound(String path, NativeDiscoveryStrategy strategy) { |
|
49 |
Log.finer("VLC NativeDiscovery: onFound " + path + " " + strategy); |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
protected void onNotFound() { |
|
54 |
Log.finer("VLC NativeDiscovery: Not found."); |
|
55 |
} |
|
56 |
}; |
|
57 |
|
|
58 |
boolean found = discovery.discover(); |
|
59 |
Log.finer("VLC NativeDiscovery: the discovery was succesfull ? " + found); |
|
60 |
if (found) { |
|
61 |
libvlc_instance_t instance = libvlc_new(0, new StringArray(new String[0])); |
|
62 |
Log.finer("VLC NativeDiscovery: VLC instance is " + instance); |
|
63 |
if (instance != null) { |
|
64 |
libvlc_release(instance); |
|
65 |
} |
|
66 |
else { |
|
67 |
Log.warning(NLS.bind("** Impossible to use your VLC [{0}] (please check that you have at least VLC version 3.0).", instance)); |
|
68 |
} |
|
69 |
Log.finer("VLC NativeDiscovery: VLC version is " + new LibVlcVersion().getVersion()); |
|
70 |
} |
|
71 |
else { |
|
72 |
Log.warning("** Impossible to find VLC (please check that you have at least VLC version 3.0)."); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
protected static final String NOMEDIA = ""; //$NON-NLS-1$ |
|
77 |
|
|
78 |
private EmbeddedMediaPlayer vlcPlayer; |
|
79 |
|
|
80 |
private Composite videoComposite; |
|
81 |
|
|
82 |
private CompositeVideoSurface playerCanvas; |
|
83 |
|
|
84 |
private Scale rateField; |
|
85 |
|
|
86 |
private Label rateValueLabel; |
|
87 |
|
|
88 |
private Scale volumeField; |
|
89 |
|
|
90 |
private Label volumeValueLabel; |
|
91 |
|
|
92 |
private Button playButton; |
|
93 |
|
|
94 |
private Button repeatButton; |
|
95 |
|
|
96 |
protected String currentlyPlayed = ""; //$NON-NLS-1$ |
|
97 |
|
|
98 |
// private String startTime, endTime; |
|
99 |
private int start, end; |
|
100 |
|
|
101 |
protected boolean hasEnded = false; |
|
102 |
|
|
103 |
private String previouslyPlayed = ""; //$NON-NLS-1$ |
|
104 |
|
|
105 |
private boolean repeat = false; |
|
106 |
|
|
107 |
protected int volume = 100; |
|
108 |
|
|
109 |
private Button stopButton; |
|
110 |
|
|
111 |
Label timeLabel; |
|
112 |
|
|
113 |
TripleRangeSlider timeRange; |
|
114 |
|
|
115 |
boolean firstLengthEvent = true; |
|
116 |
|
|
117 |
long previous = 0; |
|
118 |
|
|
119 |
long time, mins, secs; |
|
120 |
|
|
121 |
private SwtMediaPlayerFactory factory; |
|
122 |
|
|
123 |
|
|
124 |
static { |
|
125 |
// uncomment to enable VLC logs |
|
126 |
// Logger.setLevel(Level.TRACE); |
|
127 |
} |
|
128 |
|
|
129 |
public EmbeddedMediaPlayer getEmbeddedMediaPlayer() { |
|
130 |
return vlcPlayer; |
|
131 |
} |
|
132 |
|
|
133 |
Semaphore s = new Semaphore(1); |
|
134 |
|
|
135 |
public VLCPlayer(Composite parent, int style) { |
|
136 |
super(parent, style); |
|
137 |
this.setLayout(new GridLayout(11, false)); |
|
138 |
|
|
139 |
// THE PLAYER |
|
140 |
// if (RuntimeUtil.isMac()) { |
|
141 |
// try { |
|
142 |
// LibC.INSTANCE.setenv("VLC_PLUGIN_PATH", "/Applications/VLC.app/Contents/MacOS/plugins", 1); |
|
143 |
// } |
|
144 |
// catch (Exception ex) { |
|
145 |
// ex.printStackTrace(); |
|
146 |
// } |
|
147 |
// } |
|
148 |
videoComposite = new Composite(this, SWT.EMBEDDED | SWT.NO_BACKGROUND); |
|
149 |
GridData gdata = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
150 |
gdata.horizontalSpan = 11; |
|
151 |
videoComposite.setLayoutData(gdata); |
|
152 |
|
|
153 |
factory = new SwtMediaPlayerFactory(); |
|
154 |
playerCanvas = factory.swt().newCompositeVideoSurface(videoComposite); |
|
155 |
|
|
156 |
EmbeddedMediaPlayerComponent e = new EmbeddedMediaPlayerComponent(); |
|
157 |
vlcPlayer = e.mediaPlayer(); |
|
158 |
vlcPlayer.videoSurface().set(playerCanvas); |
|
159 |
|
|
160 |
videoComposite.addDisposeListener(new DisposeListener() { |
|
161 |
|
|
162 |
@Override |
|
163 |
public void widgetDisposed(DisposeEvent e) { |
|
164 |
|
|
165 |
|
|
166 |
// vlcPlayer.submit(new Runnable() { |
|
167 |
// |
|
168 |
// @Override |
|
169 |
// public void run() { |
|
170 |
// |
|
171 |
// } |
|
172 |
// }); |
|
173 |
|
|
174 |
// System.out.println("VLC STOP"); |
|
175 |
// vlcPlayer.controls().stop(); |
|
176 |
System.out.println("VLC RELEASE"); |
|
177 |
vlcPlayer.release(); |
|
178 |
System.out.println("FAC RELEASE"); |
|
179 |
factory.release(); |
|
180 |
// s.release(); |
|
181 |
} |
|
182 |
}); |
|
183 |
|
|
184 |
// THE CONTROL BUTTONS |
|
185 |
playButton = new Button(this, SWT.PUSH); |
|
186 |
GridData playLayoutData = new GridData(SWT.FILL, SWT.CENTER, false, false); |
|
187 |
playButton.setLayoutData(playLayoutData); |
|
188 |
playButton.setText(MessagesMP.play); |
|
189 |
playButton.addSelectionListener(new SelectionListener() { |
|
190 |
|
|
191 |
@Override |
|
192 |
public void widgetSelected(SelectionEvent e) { |
|
193 |
vlcPlayer.submit(new Runnable() { |
|
194 |
|
|
195 |
@Override |
|
196 |
public void run() { |
|
197 |
if (currentlyPlayed.length() == 0) { |
|
198 |
selectMedia(); |
|
199 |
playButton.setText(MessagesMP.pause); |
|
200 |
} |
|
201 |
else if (vlcPlayer.status().isPlaying()) { |
|
202 |
vlcPlayer.controls().pause(); |
|
203 |
playButton.setText(MessagesMP.resume); |
|
204 |
} |
|
205 |
else if (hasEnded) { |
|
206 |
replay(); |
|
207 |
} |
|
208 |
else { |
|
209 |
vlcPlayer.controls().play(); |
|
210 |
playButton.setText(MessagesMP.pause); |
|
211 |
} |
|
212 |
} |
|
213 |
}); |
|
214 |
} |
|
215 |
|
|
216 |
@Override |
|
217 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
218 |
}); |
|
219 |
|
|
220 |
// Button browseButton = new Button(this,SWT.PUSH); |
|
221 |
// browseButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); |
|
222 |
// browseButton.setText("Open..."); |
|
223 |
// browseButton.addSelectionListener(new SelectionListener() { |
|
224 |
// @Override |
|
225 |
// public void widgetSelected(SelectionEvent e) { |
|
226 |
// selectMedia(); |
|
227 |
// } |
|
228 |
// |
|
229 |
// @Override |
|
230 |
// public void widgetDefaultSelected(SelectionEvent e) {} |
|
231 |
// }); |
|
232 |
|
|
233 |
stopButton = new Button(this, SWT.PUSH); |
|
234 |
stopButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); |
|
235 |
stopButton.setText(MessagesMP.stop); |
|
236 |
stopButton.addSelectionListener(new SelectionListener() { |
|
237 |
|
|
238 |
@Override |
|
239 |
public void widgetSelected(SelectionEvent e) { |
|
240 |
stop(); |
|
241 |
} |
|
242 |
|
|
243 |
@Override |
|
244 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
245 |
}); |
|
246 |
|
|
247 |
timeLabel = new Label(this, SWT.NONE); |
|
248 |
timeLabel.setText("00:00"); //$NON-NLS-1$ |
|
249 |
|
|
250 |
timeRange = new TripleRangeSlider(this, SWT.None); |
|
251 |
timeRange.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
|
252 |
timeRange.setToolTipText(MessagesMP.time_range); |
|
253 |
timeRange.addSelectionListener(new SelectionListener() { |
|
254 |
|
|
255 |
@Override |
|
256 |
public void widgetSelected(SelectionEvent e) { |
|
257 |
TripleRangeSlider.SELECTED_KNOB sk = timeRange.getLastSelectedKnob(); |
|
258 |
switch (sk) { |
|
259 |
case UPPER: |
|
260 |
setStopTime(timeRange.getUpperValue()); |
|
261 |
break; |
|
262 |
case LOWER: |
|
263 |
setStartTime(timeRange.getLowerValue()); |
|
264 |
|
|
265 |
break; |
|
266 |
case MIDDLE: |
|
267 |
|
|
268 |
seek(timeRange.getMiddleValue()); |
|
269 |
|
|
270 |
break; |
|
271 |
default: |
|
272 |
// nothing |
|
273 |
} |
|
274 |
// System.out.println("time range: "+start+" -> "+end+" time="+time); |
|
275 |
} |
|
276 |
|
|
277 |
@Override |
|
278 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
279 |
}); |
|
280 |
|
|
281 |
repeatButton = new Button(this, SWT.CHECK); |
|
282 |
repeatButton.setText(MessagesMP.repeat); |
|
283 |
repeat = BackToMediaPreferences.getInstance().getBoolean(BackToMediaPreferences.REPEAT); |
|
284 |
repeatButton.setSelection(repeat); |
|
285 |
repeatButton.addSelectionListener(new SelectionListener() { |
|
286 |
|
|
287 |
@Override |
|
288 |
public void widgetSelected(SelectionEvent e) { |
|
289 |
repeat = repeatButton.getSelection(); |
|
290 |
} |
|
291 |
|
|
292 |
@Override |
|
293 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
294 |
}); |
|
295 |
|
|
296 |
Label l = new Label(this, SWT.NONE); |
|
297 |
l.setText(MessagesMP.rate); |
|
298 |
|
|
299 |
rateField = new Scale(this, SWT.BORDER); |
|
300 |
GridData gdata4 = new GridData(SWT.FILL, SWT.CENTER, false, false); |
|
301 |
gdata4.widthHint = 100; |
|
302 |
rateField.setLayoutData(gdata4); |
|
303 |
rateField.setMaximum(140); |
|
304 |
rateField.setMinimum(70); |
|
305 |
rateField.setSelection(100); |
|
306 |
rateField.setPageIncrement(5); |
|
307 |
|
|
308 |
rateField.addSelectionListener(new SelectionListener() { |
|
309 |
|
|
310 |
@Override |
|
311 |
public void widgetSelected(SelectionEvent e) { |
|
312 |
float rate = rateField.getSelection() / 100.0f; |
|
313 |
vlcPlayer.controls().setRate(rate); |
|
314 |
rateValueLabel.setText("" + rateField.getSelection() + "%"); |
|
315 |
} |
|
316 |
|
|
317 |
@Override |
|
318 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
319 |
}); |
|
320 |
|
|
321 |
rateValueLabel = new Label(this, SWT.NONE); |
|
322 |
rateValueLabel.setText("100%");//$NON-NLS-1$ |
|
323 |
|
|
324 |
l = new Label(this, SWT.NONE); |
|
325 |
l.setText(MessagesMP.volume); |
|
326 |
|
|
327 |
volumeField = new Scale(this, SWT.BORDER); |
|
328 |
gdata4 = new GridData(SWT.FILL, SWT.CENTER, false, false); |
|
329 |
gdata4.widthHint = 100; |
|
330 |
volumeField.setLayoutData(gdata4); |
|
331 |
volumeField.setMinimum(0); |
|
332 |
volumeField.setMaximum(100); |
|
333 |
volumeField.setSelection(volume); |
|
334 |
volumeField.setPageIncrement(5); |
|
335 |
volumeField.addSelectionListener(new SelectionListener() { |
|
336 |
|
|
337 |
@Override |
|
338 |
public void widgetSelected(SelectionEvent e) { |
|
339 |
vlcPlayer.audio().setVolume(volumeField.getSelection()); |
|
340 |
volume = volumeField.getSelection(); |
|
341 |
volumeValueLabel.setText("" + volume + "%"); |
|
342 |
} |
|
343 |
|
|
344 |
@Override |
|
345 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
346 |
}); |
|
347 |
|
|
348 |
volumeValueLabel = new Label(this, SWT.NONE); |
|
349 |
volumeValueLabel.setText("100%"); |
|
350 |
|
|
351 |
vlcPlayer.events().addMediaPlayerEventListener(new MediaPlayerEventAdapter() { |
|
352 |
|
|
353 |
@Override |
|
354 |
public void opening(MediaPlayer mediaPlayer) { |
|
355 |
if (videoComposite.isDisposed()) return; |
|
356 |
Log.finer("Opening media..."); |
|
357 |
} |
|
358 |
|
|
359 |
@Override |
|
360 |
public void finished(MediaPlayer mediaPlayer) { |
|
361 |
if (videoComposite.isDisposed()) return; |
|
362 |
Log.finer("Finished playing media..."); |
|
363 |
mediaPlayer.submit(new Runnable() { |
|
364 |
|
|
365 |
@Override |
|
366 |
public void run() { |
|
367 |
if (repeat) { |
|
368 |
replay(); |
|
369 |
} |
|
370 |
else { |
|
371 |
hasEnded = true; |
|
372 |
} |
|
373 |
} |
|
374 |
}); |
|
375 |
} |
|
376 |
}); |
|
377 |
|
|
378 |
vlcPlayer.events().addMediaPlayerEventListener(new MediaPlayerEventAdapter() { |
|
379 |
|
|
380 |
@Override |
|
381 |
public void timeChanged(MediaPlayer mediaPlayer, final long arg1) { |
|
382 |
if (videoComposite.isDisposed()) return; |
|
383 |
|
|
384 |
mediaPlayer.submit(new Runnable() { |
|
385 |
|
|
386 |
@Override |
|
387 |
public void run() { |
|
388 |
time = arg1; |
|
389 |
if (previous == time) { |
|
390 |
return; |
|
391 |
} |
|
392 |
previous = time; |
|
393 |
|
|
394 |
timeLabel.getDisplay().syncExec(new Runnable() { |
|
395 |
|
|
396 |
@Override |
|
397 |
public void run() { |
|
398 |
if (timeRange.isDisposed()) { |
|
399 |
return; |
|
400 |
} |
|
401 |
if (!timeRange.isDragMiddleKnob()) { |
|
402 |
timeRange.setMiddleValue((int) time); |
|
403 |
} |
|
404 |
updateTimeLabel(); |
|
405 |
|
|
406 |
if (arg1 > end && end != start) { |
|
407 |
// System.out.println("Time > end :"+arg1 +" > "+end); |
|
408 |
if (repeat) { |
|
409 |
vlcPlayer.controls().setTime(start); |
|
410 |
} |
|
411 |
else { |
|
412 |
vlcPlayer.controls().stop(); |
|
413 |
} |
|
414 |
} |
|
415 |
} |
|
416 |
}); |
|
417 |
} |
|
418 |
}); |
|
419 |
} |
|
420 |
|
|
421 |
@Override |
|
422 |
public void lengthChanged(MediaPlayer mediaPlayer, final long arg1) { |
|
423 |
if (videoComposite.isDisposed()) return; |
|
424 |
|
|
425 |
mediaPlayer.submit(new Runnable() { |
|
426 |
|
|
427 |
@Override |
|
428 |
public void run() { |
|
429 |
if (firstLengthEvent) { |
|
430 |
firstLengthEvent = false; |
|
431 |
|
|
432 |
// initialize time range widget limits |
|
433 |
timeRange.getDisplay().syncExec(new Runnable() { |
|
434 |
|
|
435 |
@Override |
|
436 |
public void run() { |
|
437 |
if (timeRange.isDisposed()) return; |
|
438 |
timeRange.setMaximum((int) arg1); |
|
439 |
// if (start == end) end = (int)arg1; |
|
440 |
|
|
441 |
|
|
442 |
if (end > 0 && start != end) { |
|
443 |
timeRange.setUpperValue(end); |
|
444 |
} |
|
445 |
else { |
|
446 |
timeRange.setUpperValue((int) arg1); |
|
447 |
} |
|
448 |
|
|
449 |
timeRange.setLowerValue(start); |
|
450 |
// System.out.println("Range: "+start+" -> "+end+" song length "+arg1); |
|
451 |
} |
|
452 |
}); |
|
453 |
} |
|
454 |
} |
|
455 |
}); |
|
456 |
} |
|
457 |
}); |
|
458 |
} |
|
459 |
|
|
460 |
private void updateTimeLabel() { |
|
461 |
mins = time / 60000; |
|
462 |
secs = (time / 1000) % 60; |
|
463 |
timeLabel.setText(String.format("%02d:%02d", mins, secs)); //$NON-NLS-1$ |
|
464 |
timeLabel.update(); |
|
465 |
} |
|
466 |
|
|
467 |
public void replay() { |
|
468 |
if (currentlyPlayed.length() > 0) { |
|
469 |
// this.play(currentlyPlayed, startTime, endTime); |
|
470 |
vlcPlayer.submit(new Runnable() { |
|
471 |
|
|
472 |
@Override |
|
473 |
public void run() { |
|
474 |
vlcPlayer.controls().setTime(start); |
|
475 |
} |
|
476 |
}); |
|
477 |
|
|
478 |
playButton.setText(MessagesMP.pause); |
|
479 |
} |
|
480 |
} |
|
481 |
|
|
482 |
protected void selectMedia() { |
|
483 |
Log.fine(MessagesMP.select_file); |
|
484 |
|
|
485 |
FileDialog fd = new FileDialog(VLCPlayer.this.getShell(), SWT.OPEN); |
|
486 |
fd.setText(MessagesMP.select_file_title); |
|
487 |
File f = new File(previouslyPlayed); |
|
488 |
if (f.isDirectory()) fd.setFilterPath(f.getPath()); |
|
489 |
else fd.setFilterPath(f.getParent()); |
|
490 |
|
|
491 |
String[] filterExt = { "*.*", "*.mp3", "*.mp4", "*.avi" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
492 |
fd.setFilterExtensions(filterExt); |
|
493 |
String selected = fd.open(); |
|
494 |
if (selected == null) { |
|
495 |
System.out.println(MessagesMP.cancel); |
|
496 |
return; |
|
497 |
} |
|
498 |
|
|
499 |
currentlyPlayed = selected; |
|
500 |
previouslyPlayed = selected; |
|
501 |
Log.fine(MessagesMP.opening + currentlyPlayed); |
|
502 |
play(currentlyPlayed, 0, 0); |
|
503 |
} |
|
504 |
|
|
505 |
/** |
|
506 |
* |
|
507 |
* @param mrl |
|
508 |
* @param time msec start time |
|
509 |
* @param endtime msec end time |
|
510 |
*/ |
|
511 |
@Override |
|
512 |
public boolean play(String mrl, int time, int endtime) { |
|
513 |
Log.fine(MessagesMP.bind(MessagesMP.playing, new Object[] { mrl, time, endtime })); |
|
514 |
return play(mrl, "" + time / 1000.0f, "" + endtime / 1000.0f); //$NON-NLS-1$ //$NON-NLS-2$ |
|
515 |
} |
|
516 |
|
|
517 |
@Override |
|
518 |
public boolean play(String mrl, int time) { |
|
519 |
return play(mrl, time, time); |
|
520 |
} |
|
521 |
|
|
522 |
public void hideStopButton() { |
|
523 |
if (this.stopButton != null && !this.stopButton.isDisposed()) { |
|
524 |
this.stopButton.dispose(); |
|
525 |
} |
|
526 |
} |
|
527 |
|
|
528 |
DateTimeFormatter hhmmssFormatter = DateTimeFormatter.ISO_LOCAL_TIME; |
|
529 |
|
|
530 |
private boolean authenticatedURLMode = false; |
|
531 |
|
|
532 |
/** |
|
533 |
* |
|
534 |
* @param mrl |
|
535 |
* @param startTime "0.0" or ""hh:mm:ss" format |
|
536 |
* @param endTime "0.0" or ""hh:mm:ss" format |
|
537 |
*/ |
|
538 |
@Override |
|
539 |
public boolean play(String mrl, String startTime, String endTime) { |
|
540 |
|
|
541 |
if (startTime.matches("[0-9]+.[0-9]+")) { |
|
542 |
start = (int) (1000 * Float.parseFloat(startTime)); |
|
543 |
} |
|
544 |
else if (startTime.matches("[0-9]+:[0-9]+:[0-9]+")) { |
|
545 |
if (startTime.indexOf(":") == 1) { |
|
546 |
startTime = "0" + startTime; |
|
547 |
} |
|
548 |
LocalTime time1 = LocalTime.parse(startTime, hhmmssFormatter); |
|
549 |
start = 1000 * ((time1.getHour() * 60 * 60) + (time1.getMinute() * 60) + time1.getSecond()); |
|
550 |
} |
|
551 |
|
|
552 |
if (endTime.matches("[0-9]+.[0-9]+")) { |
|
553 |
end = (int) (1000 * Float.parseFloat(endTime)); |
|
554 |
} |
|
555 |
else if (endTime.matches("[0-9]+:[0-9]+:[0-9]+")) { |
|
556 |
if (endTime.indexOf(":") == 1) endTime = "0" + endTime; |
|
557 |
LocalTime time1 = LocalTime.parse(endTime, hhmmssFormatter); |
|
558 |
end = 1000 * ((time1.getHour() * 60 * 60) + (time1.getMinute() * 60) + time1.getSecond()); |
|
559 |
} |
|
560 |
|
|
561 |
// if (start == end) end = -1; |
|
562 |
|
|
563 |
Log.finer(MessagesMP.bind(MessagesMP.playing, new Object[] { mrl, startTime, endTime })); |
|
564 |
|
|
565 |
String[] options = { " :live-caching=200" }; // reduce video stream cache duration to 200ms |
|
566 |
|
|
567 |
Log.finer("Preparing media..."); |
|
568 |
|
|
569 |
// inserting login+mdp |
|
570 |
String tmp = null; |
|
571 |
if (authenticatedURLMode && mrl.contains("{0}") && mrl.contains("{1}") |
|
572 |
&& System.getProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN) != null && System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD) != null) { |
|
573 |
tmp = NLS.bind(mrl, System.getProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN), System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD)); |
|
574 |
} |
|
575 |
|
|
576 |
// use the patched URL if authenticatedURL is true |
|
577 |
if (authenticatedURLMode && tmp != null) { |
|
578 |
if (!vlcPlayer.media().prepare(tmp, options)) { |
|
579 |
Log.finer("** Impossible to prepare media."); |
|
580 |
return false; |
|
581 |
} |
|
582 |
} |
|
583 |
else { |
|
584 |
if (!vlcPlayer.media().prepare(mrl, options)) { |
|
585 |
Log.finer("** Impossible to prepare media."); |
|
586 |
return false; |
|
587 |
} |
|
588 |
} |
|
589 |
|
|
590 |
Log.finer("Is media valid ?"); |
|
591 |
if (!vlcPlayer.media().isValid()) { |
|
592 |
Log.finer("** Invalid media."); |
|
593 |
return false; |
|
594 |
} |
|
595 |
|
|
596 |
Log.info("Playing media..."); |
|
597 |
vlcPlayer.controls().play(); |
|
598 |
vlcPlayer.audio().setVolume(volume); |
|
599 |
vlcPlayer.controls().setTime(start); |
|
600 |
|
|
601 |
if (new File(mrl + ".srt").exists()) { //$NON-NLS-1$ |
|
602 |
vlcPlayer.subpictures().setSubTitleFile(mrl + ".srt"); //$NON-NLS-1$ |
|
603 |
} |
|
604 |
currentlyPlayed = mrl; |
|
605 |
previouslyPlayed = mrl; |
|
606 |
|
|
607 |
if (!playButton.isDisposed()) { |
|
608 |
playButton.setText(MessagesMP.pause); |
|
609 |
} |
|
610 |
firstLengthEvent = true; |
|
611 |
|
|
612 |
return true; |
|
613 |
} |
|
614 |
|
|
615 |
/** |
|
616 |
* for more test use "player.getEmbeddedMediaPlayer()" |
|
617 |
* |
|
618 |
* @return false if the media could not be loaded (file not found, access error...) |
|
619 |
*/ |
|
620 |
@Override |
|
621 |
public boolean isMediaLoaded() { |
|
622 |
return getEmbeddedMediaPlayer().status().isPlayable(); |
|
623 |
} |
|
624 |
|
|
625 |
@Override |
|
626 |
public void setRepeat(boolean repeat) { |
|
627 |
this.repeat = repeat; |
|
628 |
repeatButton.setSelection(repeat); |
|
629 |
} |
|
630 |
|
|
631 |
@Override |
|
632 |
public void stop() { |
|
633 |
vlcPlayer.controls().stop(); |
|
634 |
currentlyPlayed = NOMEDIA; |
|
635 |
if (!playButton.isDisposed()) { |
|
636 |
playButton.setText(MessagesMP.play); |
|
637 |
} |
|
638 |
} |
|
639 |
|
|
640 |
@Override |
|
641 |
public final void setCredentials(String login, String mdp) { |
|
642 |
if (login != null && mdp != null) { |
|
643 |
authenticatedURLMode = true; |
|
644 |
} |
|
645 |
else { |
|
646 |
authenticatedURLMode = false; |
|
647 |
} |
|
648 |
} |
|
649 |
|
|
650 |
@Override |
|
651 |
public void seek(float time) { |
|
652 |
|
|
653 |
// vlcPlayer.controls().setPosition(time); |
|
654 |
time = timeRange.getMiddleValue(); |
|
655 |
// System.out.println("Middle changed: fix time: "+time); |
|
656 |
vlcPlayer.controls().setPosition(time); |
|
657 |
} |
|
658 |
|
|
659 |
@Override |
|
660 |
public void pause() { |
|
661 |
|
|
662 |
vlcPlayer.controls().pause(); |
|
663 |
|
|
664 |
} |
|
665 |
|
|
666 |
@Override |
|
667 |
public void resume() { |
|
668 |
|
|
669 |
vlcPlayer.controls().play(); |
|
670 |
|
|
671 |
} |
|
672 |
|
|
673 |
@Override |
|
674 |
public void setVolume(double volume) { |
|
675 |
|
|
676 |
vlcPlayer.audio().setVolume(volumeField.getSelection()); |
|
677 |
} |
|
678 |
|
|
679 |
@Override |
|
680 |
public void setRate(float rate) { |
|
681 |
|
|
682 |
vlcPlayer.controls().setRate(rate); |
|
683 |
|
|
684 |
} |
|
685 |
|
|
686 |
@Override |
|
687 |
public boolean isPlaying() { |
|
688 |
|
|
689 |
return vlcPlayer.status().isPlaying(); |
|
690 |
} |
|
691 |
|
|
692 |
@Override |
|
693 |
public void setStartTime(float seconds) { |
|
694 |
|
|
695 |
start = timeRange.getLowerValue(); |
|
696 |
if (start > time) { |
|
697 |
// System.out.println("Lower changed: fix time"); |
|
698 |
time = start; |
|
699 |
vlcPlayer.controls().setTime(time); |
|
700 |
} |
Formats disponibles : Unified diff