Révision 2445
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/SimpleFileDialog.java (revision 2445) | ||
---|---|---|
5 | 5 |
import org.eclipse.swt.SWT; |
6 | 6 |
import org.eclipse.swt.events.SelectionEvent; |
7 | 7 |
import org.eclipse.swt.events.SelectionListener; |
8 |
import org.eclipse.swt.layout.GridData; |
|
9 |
import org.eclipse.swt.layout.GridLayout; |
|
8 | 10 |
import org.eclipse.swt.widgets.Button; |
9 | 11 |
import org.eclipse.swt.widgets.Composite; |
10 | 12 |
import org.eclipse.swt.widgets.Control; |
... | ... | |
21 | 23 |
|
22 | 24 |
@Override |
23 | 25 |
protected Control createDialogArea(Composite parent) { |
24 |
Control p = super.createDialogArea(parent);
|
|
26 |
Composite p = (Composite) super.createDialogArea(parent);
|
|
25 | 27 |
|
26 |
selectButton = new Button(parent, SWT.PUSH); |
|
28 |
GridLayout layout = (GridLayout) p.getLayout(); |
|
29 |
layout.numColumns = layout.numColumns + 1; |
|
30 |
|
|
31 |
getText().setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false, 2, 1)); |
|
32 |
setErrorMessage(null); |
|
33 |
selectButton = new Button(p, SWT.PUSH); |
|
34 |
selectButton.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true)); |
|
27 | 35 |
selectButton.setText("..."); |
28 | 36 |
selectButton.addSelectionListener(new SelectionListener() { |
29 | 37 |
|
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/BackToMedia.java (revision 2445) | ||
---|---|---|
399 | 399 |
String media_directory = commandPreferences.get(BackToMediaPreferences.MEDIA_PATH_PREFIX, alternative); |
400 | 400 |
boolean media_auth = "true".equals(commandPreferences.get(BackToMediaPreferences.MEDIA_AUTH, alternative)); |
401 | 401 |
String secured_media_login = commandPreferences.get(BackToMediaPreferences.MEDIA_AUTH_LOGIN, alternative); |
402 |
String secured_media_password = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD); |
|
403 | 402 |
String media_format = commandPreferences.get(BackToMediaPreferences.MEDIA_EXTENSION, alternative); |
404 | 403 |
String media_index = commandPreferences.get(BackToMediaPreferences.MEDIA_INDEX_NODE, alternative); |
405 | 404 |
|
... | ... | |
434 | 433 |
String path_prefix = media_directory; |
435 | 434 |
if (media_auth) { |
436 | 435 |
|
437 |
if (secured_media_password == null) {
|
|
436 |
if (System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD) == null) {
|
|
438 | 437 |
URL url = new URL(media_directory); |
439 | 438 |
|
440 | 439 |
UsernamePasswordDialog dialog = new UsernamePasswordDialog(shell, new boolean[] { true, true }, url.getHost()); |
... | ... | |
442 | 441 |
dialog.setTitle("You must authenticate to access the media file"); |
443 | 442 |
dialog.setDetails(NLS.bind(TXMUIMessages.loginToP0, new URL(media_directory).getHost())); |
444 | 443 |
if (dialog.open() == dialog.OK) { |
444 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN, dialog.getUser()); |
|
445 | 445 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, dialog.getPassword()); |
446 |
secured_media_password = dialog.getPassword(); |
|
447 | 446 |
} |
448 | 447 |
else { |
448 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN, null); |
|
449 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, null); |
|
449 | 450 |
return null; |
450 | 451 |
} |
451 | 452 |
} |
452 |
path_prefix = NLS.bind(media_directory, secured_media_login, secured_media_password); |
|
453 | 453 |
} |
454 | 454 |
|
455 | 455 |
File audioFile = new File(path_prefix, textid + "." + media_format); //$NON-NLS-1$ |
... | ... | |
505 | 505 |
vlcEditor = associatedEditors.get(editor); |
506 | 506 |
} |
507 | 507 |
|
508 |
if (vlcEditor == null) { |
|
508 |
if (vlcEditor == null || vlcEditor.getPlayer().isDisposed()) {
|
|
509 | 509 |
// System.out.println("new editor linked to "+ce); |
510 | 510 |
vlcEditor = OpenVLCPlayer.openEditor(); |
511 | 511 |
|
... | ... | |
521 | 521 |
SWTEditorsUtils.addEditor((EditorPart) editor, vlcEditor, position); |
522 | 522 |
} |
523 | 523 |
|
524 |
VLCPlayer player = vlcEditor.getPlayer();
|
|
524 |
Object player = vlcEditor.getPlayer();
|
|
525 | 525 |
if (player != null) { |
526 |
player.hideStopButton(); |
|
526 |
// player.hideStopButton();
|
|
527 | 527 |
associatedEditors.put(editor, vlcEditor); |
528 | 528 |
} |
529 | 529 |
} |
530 | 530 |
|
531 |
if (media_auth) { |
|
532 |
// path_prefix = NLS.bind(media_directory, secured_media_login, secured_media_password); |
|
533 |
vlcEditor.getPlayer().setCredentials(System.getProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN), System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD)); |
|
534 |
} |
|
531 | 535 |
vlcEditor.getPlayer().play(path, sStartTime, sEndTime); |
532 | 536 |
vlcEditor.getPlayer().setRepeat(true); |
533 | 537 |
|
534 |
if (!vlcEditor.isMediaLoaded()) { |
|
535 |
|
|
536 |
vlcEditor.getSite().getPage().closeEditor(vlcEditor, false);
|
|
537 |
if (media_auth) {
|
|
538 |
Log.warning("The MediaPlayer could not open the media: " + media_directory); // don't show credentials
|
|
539 |
System.clearProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD);
|
|
540 |
System.clearProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN);
|
|
541 |
}
|
|
542 |
else {
|
|
543 |
Log.warning("The MediaPlayer could not open the media: " + path);
|
|
544 |
}
|
|
545 |
} |
|
538 |
// if (!vlcEditor.isMediaLoaded()) {
|
|
539 |
// |
|
540 |
// vlcEditor.getSite().getPage().closeEditor(vlcEditor, false);
|
|
541 |
// if (media_auth) {
|
|
542 |
// Log.warning("The MediaPlayer could not open the media: " + media_directory); // don't show credentials
|
|
543 |
// System.clearProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD);
|
|
544 |
// System.clearProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN);
|
|
545 |
// }
|
|
546 |
// else {
|
|
547 |
// Log.warning("The MediaPlayer could not open the media: " + path);
|
|
548 |
// }
|
|
549 |
// }
|
|
546 | 550 |
|
547 | 551 |
if (path != null) { |
548 | 552 |
vlcEditor.setPartName(textid); |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/OpenVLCPlayer.java (revision 2445) | ||
---|---|---|
28 | 28 |
package org.txm.backtomedia.commands.function; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
import java.io.UnsupportedEncodingException; |
|
32 |
import java.net.URLEncoder; |
|
31 | 33 |
|
32 | 34 |
import org.eclipse.core.commands.AbstractHandler; |
33 | 35 |
import org.eclipse.core.commands.ExecutionEvent; |
... | ... | |
89 | 91 |
// fd.setFilterExtensions(filterExt); |
90 | 92 |
if (fd.open() == fd.OK) { |
91 | 93 |
String mrl = fd.getValue(); |
92 |
if (mrl != null) |
|
94 |
|
|
95 |
if (mrl != null) { |
|
96 |
File f = new File(mrl); |
|
97 |
if (f.exists()) { |
|
98 |
mrl = new File(mrl).toURI().toString(); |
|
99 |
} |
|
100 |
else { |
|
101 |
|
|
102 |
} |
|
93 | 103 |
openEditor(mrl, 0); |
104 |
} |
|
94 | 105 |
} |
95 | 106 |
|
96 | 107 |
return null; |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/preferences/BackToMediaPreferencePage.java (revision 2445) | ||
---|---|---|
83 | 83 |
|
84 | 84 |
private Group spanGroup; |
85 | 85 |
|
86 |
private ComboFieldEditor playerProperty; |
|
87 |
|
|
86 | 88 |
/** |
87 | 89 |
* Instantiates a new diagnostic preference page. |
88 | 90 |
*/ |
... | ... | |
153 | 155 |
addField(defaultStructureEndProperty); |
154 | 156 |
|
155 | 157 |
updateEnables(BackToMediaPreferences.getInstance().getString(BackToMediaPreferences.SYNCMODE)); |
158 |
|
|
159 |
String[][] players = { { "JFX", "JFX" }, { "VLC", "VLC" } }; |
|
160 |
playerProperty = new ComboFieldEditor(BackToMediaPreferences.PLAYER, "Embedded player", players, getFieldEditorParent()); |
|
161 |
addField(playerProperty); |
|
156 | 162 |
} |
157 | 163 |
|
158 | 164 |
public void updateEnables(String sync_mode) { |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/preferences/BackToMediaPreferences.java (revision 2445) | ||
---|---|---|
31 | 31 |
|
32 | 32 |
// the sync modes |
33 | 33 |
public static final String WORDMODE = "Word"; |
34 |
|
|
34 | 35 |
public static final String STRUCTUREMODE = "Structure"; |
36 |
|
|
35 | 37 |
public static final String MILESTONEMODE = "Milestone"; |
36 | 38 |
|
37 | 39 |
public static final String MEDIA_PATH_PREFIX = "media_path_prefix"; |
... | ... | |
54 | 56 |
*/ |
55 | 57 |
public static final String BACKTOMEDIA_POSITION = "backtomedia_position"; //$NON-NLS-1$ |
56 | 58 |
|
59 |
public static final String PLAYER = "player"; |
|
60 |
|
|
57 | 61 |
public BackToMediaPreferences() { |
58 | 62 |
// TODO Auto-generated constructor stub |
59 | 63 |
} |
... | ... | |
63 | 67 |
super.initializeDefaultPreferences(); |
64 | 68 |
|
65 | 69 |
Preferences preferences = DefaultScope.INSTANCE.getNode(getPreferencesNodeQualifier()); |
70 |
preferences.put(PLAYER, "JFX"); |
|
66 | 71 |
preferences.putBoolean(REPEAT, true); |
67 | 72 |
preferences.put(SYNCMODE, MILESTONEMODE); |
68 | 73 |
preferences.put(STRUCTURE, "u"); |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/editors/vlcplayer/VLCPlayer.java (revision 2445) | ||
---|---|---|
6 | 6 |
import java.io.File; |
7 | 7 |
import java.time.LocalTime; |
8 | 8 |
import java.time.format.DateTimeFormatter; |
9 |
import java.util.concurrent.Semaphore; |
|
9 | 10 |
|
10 | 11 |
import org.eclipse.osgi.util.NLS; |
11 | 12 |
import org.eclipse.swt.SWT; |
... | ... | |
26 | 27 |
|
27 | 28 |
import com.sun.jna.StringArray; |
28 | 29 |
|
29 |
import uk.co.caprica.vlcj.binding.LibC; |
|
30 |
import uk.co.caprica.vlcj.binding.RuntimeUtil; |
|
31 | 30 |
import uk.co.caprica.vlcj.binding.internal.libvlc_instance_t; |
32 | 31 |
import uk.co.caprica.vlcj.factory.discovery.NativeDiscovery; |
33 | 32 |
import uk.co.caprica.vlcj.factory.discovery.strategy.NativeDiscoveryStrategy; |
34 | 33 |
import uk.co.caprica.vlcj.factory.swt.SwtMediaPlayerFactory; |
35 |
import uk.co.caprica.vlcj.media.MediaRef; |
|
36 | 34 |
import uk.co.caprica.vlcj.player.base.MediaPlayer; |
37 | 35 |
import uk.co.caprica.vlcj.player.base.MediaPlayerEventAdapter; |
38 | 36 |
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent; |
... | ... | |
41 | 39 |
import uk.co.caprica.vlcj.support.version.LibVlcVersion; |
42 | 40 |
import vlcplayerrcp.MessagesMP; |
43 | 41 |
|
44 |
public class VLCPlayer extends Composite { |
|
42 |
public class VLCPlayer extends Composite implements IPlayer {
|
|
45 | 43 |
|
46 | 44 |
static { // force native libs discovery -> fix Mac OS X init |
47 | 45 |
NativeDiscovery discovery = new NativeDiscovery() { |
... | ... | |
56 | 54 |
Log.finer("VLC NativeDiscovery: Not found."); |
57 | 55 |
} |
58 | 56 |
}; |
57 |
|
|
59 | 58 |
boolean found = discovery.discover(); |
60 | 59 |
Log.finer("VLC NativeDiscovery: the discovery was succesfull ? " + found); |
61 | 60 |
if (found) { |
... | ... | |
63 | 62 |
Log.finer("VLC NativeDiscovery: VLC instance is " + instance); |
64 | 63 |
if (instance != null) { |
65 | 64 |
libvlc_release(instance); |
66 |
} else { |
|
65 |
} |
|
66 |
else { |
|
67 | 67 |
Log.warning(NLS.bind("** Impossible to use your VLC [{0}] (please check that you have at least VLC version 3.0).", instance)); |
68 | 68 |
} |
69 | 69 |
Log.finer("VLC NativeDiscovery: VLC version is " + new LibVlcVersion().getVersion()); |
70 |
} else { |
|
70 |
} |
|
71 |
else { |
|
71 | 72 |
Log.warning("** Impossible to find VLC (please check that you have at least VLC version 3.0)."); |
72 | 73 |
} |
73 | 74 |
} |
... | ... | |
129 | 130 |
return vlcPlayer; |
130 | 131 |
} |
131 | 132 |
|
133 |
Semaphore s = new Semaphore(1); |
|
134 |
|
|
132 | 135 |
public VLCPlayer(Composite parent, int style) { |
133 | 136 |
super(parent, style); |
134 | 137 |
this.setLayout(new GridLayout(11, false)); |
... | ... | |
158 | 161 |
|
159 | 162 |
@Override |
160 | 163 |
public void widgetDisposed(DisposeEvent e) { |
161 |
vlcPlayer.controls().stop(); |
|
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"); |
|
162 | 177 |
vlcPlayer.release(); |
178 |
System.out.println("FAC RELEASE"); |
|
163 | 179 |
factory.release(); |
180 |
// s.release(); |
|
164 | 181 |
} |
165 | 182 |
}); |
166 | 183 |
|
... | ... | |
346 | 363 |
|
347 | 364 |
@Override |
348 | 365 |
public void opening(MediaPlayer mediaPlayer) { |
366 |
if (videoComposite.isDisposed()) return; |
|
349 | 367 |
Log.finer("Opening media..."); |
350 | 368 |
} |
351 | 369 |
|
352 | 370 |
@Override |
353 | 371 |
public void finished(MediaPlayer mediaPlayer) { |
372 |
if (videoComposite.isDisposed()) return; |
|
354 | 373 |
Log.finer("Finished playing media..."); |
355 | 374 |
mediaPlayer.submit(new Runnable() { |
356 | 375 |
|
... | ... | |
371 | 390 |
|
372 | 391 |
@Override |
373 | 392 |
public void timeChanged(MediaPlayer mediaPlayer, final long arg1) { |
393 |
if (videoComposite.isDisposed()) return; |
|
374 | 394 |
|
375 | 395 |
mediaPlayer.submit(new Runnable() { |
376 | 396 |
|
... | ... | |
411 | 431 |
|
412 | 432 |
@Override |
413 | 433 |
public void lengthChanged(MediaPlayer mediaPlayer, final long arg1) { |
434 |
if (videoComposite.isDisposed()) return; |
|
414 | 435 |
|
415 | 436 |
mediaPlayer.submit(new Runnable() { |
416 | 437 |
|
... | ... | |
498 | 519 |
* @param time msec start time |
499 | 520 |
* @param endtime msec end time |
500 | 521 |
*/ |
501 |
public void play(String mrl, int time, int endtime) { |
|
522 |
@Override |
|
523 |
public boolean play(String mrl, int time, int endtime) { |
|
502 | 524 |
Log.fine(MessagesMP.bind(MessagesMP.playing, new Object[] { mrl, time, endtime })); |
503 |
play(mrl, "" + time / 1000.0f, "" + endtime / 1000.0f); //$NON-NLS-1$ //$NON-NLS-2$ |
|
525 |
return play(mrl, "" + time / 1000.0f, "" + endtime / 1000.0f); //$NON-NLS-1$ //$NON-NLS-2$
|
|
504 | 526 |
} |
505 | 527 |
|
506 |
public void play(String mrl, int time) { |
|
507 |
play(mrl, time, time); |
|
528 |
@Override |
|
529 |
public boolean play(String mrl, int time) { |
|
530 |
return play(mrl, time, time); |
|
508 | 531 |
} |
509 | 532 |
|
510 | 533 |
public void hideStopButton() { |
... | ... | |
515 | 538 |
|
516 | 539 |
DateTimeFormatter hhmmssFormatter = DateTimeFormatter.ISO_LOCAL_TIME; |
517 | 540 |
|
541 |
private boolean authenticatedURLMode = false; |
|
542 |
|
|
518 | 543 |
/** |
519 | 544 |
* |
520 | 545 |
* @param mrl |
521 | 546 |
* @param startTime "0.0" or ""hh:mm:ss" format |
522 | 547 |
* @param endTime "0.0" or ""hh:mm:ss" format |
523 | 548 |
*/ |
549 |
@Override |
|
524 | 550 |
public boolean play(String mrl, String startTime, String endTime) { |
525 | 551 |
|
526 | 552 |
if (startTime.matches("[0-9]+.[0-9]+")) { |
... | ... | |
546 | 572 |
// if (start == end) end = -1; |
547 | 573 |
|
548 | 574 |
Log.finer(MessagesMP.bind(MessagesMP.playing, new Object[] { mrl, startTime, endTime })); |
549 |
// vlcPlayer.submit(new Runnable() { |
|
550 |
// |
|
551 |
// @Override |
|
552 |
// public void run() { |
|
575 |
|
|
553 | 576 |
String[] options = { " :live-caching=200" }; // reduce video stream cache duration to 200ms |
554 | 577 |
|
555 | 578 |
Log.finer("Preparing media..."); |
556 |
if (!vlcPlayer.media().prepare(mrl, options)) { |
|
557 |
Log.finer("** Impossible to prepare media."); |
|
558 |
return false; |
|
579 |
|
|
580 |
// inserting login+mdp |
|
581 |
String tmp = null; |
|
582 |
if (authenticatedURLMode && mrl.contains("{0}") && mrl.contains("{1}") |
|
583 |
&& System.getProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN) != null && System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD) != null) { |
|
584 |
tmp = NLS.bind(mrl, System.getProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN), System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD)); |
|
559 | 585 |
} |
560 | 586 |
|
587 |
// use the patched URL if authenticatedURL is true |
|
588 |
if (authenticatedURLMode && tmp != null) { |
|
589 |
if (!vlcPlayer.media().prepare(tmp, options)) { |
|
590 |
Log.finer("** Impossible to prepare media."); |
|
591 |
return false; |
|
592 |
} |
|
593 |
} |
|
594 |
else { |
|
595 |
if (!vlcPlayer.media().prepare(mrl, options)) { |
|
596 |
Log.finer("** Impossible to prepare media."); |
|
597 |
return false; |
|
598 |
} |
|
599 |
} |
|
600 |
|
|
561 | 601 |
Log.finer("Is media valid ?"); |
562 | 602 |
if (!vlcPlayer.media().isValid()) { |
563 | 603 |
Log.finer("** Invalid media."); |
... | ... | |
575 | 615 |
currentlyPlayed = mrl; |
576 | 616 |
previouslyPlayed = mrl; |
577 | 617 |
|
578 |
playButton.setText(MessagesMP.pause); |
|
618 |
if (!playButton.isDisposed()) { |
|
619 |
playButton.setText(MessagesMP.pause); |
|
620 |
} |
|
579 | 621 |
firstLengthEvent = true; |
580 |
// } |
|
581 |
// }); |
|
622 |
|
|
582 | 623 |
return true; |
583 | 624 |
} |
584 | 625 |
|
626 |
/** |
|
627 |
* for more test use "player.getEmbeddedMediaPlayer()" |
|
628 |
* |
|
629 |
* @return false if the media could not be loaded (file not found, access error...) |
|
630 |
*/ |
|
631 |
@Override |
|
632 |
public boolean isMediaLoaded() { |
|
633 |
return getEmbeddedMediaPlayer().status().isPlayable(); |
|
634 |
} |
|
635 |
|
|
636 |
@Override |
|
585 | 637 |
public void setRepeat(boolean repeat) { |
586 | 638 |
this.repeat = repeat; |
587 | 639 |
repeatButton.setSelection(repeat); |
588 | 640 |
} |
589 | 641 |
|
642 |
@Override |
|
590 | 643 |
public void stop() { |
591 | 644 |
vlcPlayer.controls().stop(); |
592 | 645 |
currentlyPlayed = NOMEDIA; |
... | ... | |
594 | 647 |
playButton.setText(MessagesMP.play); |
595 | 648 |
} |
596 | 649 |
} |
650 |
|
|
651 |
@Override |
|
652 |
public final void setCredentials(String login, String mdp) { |
|
653 |
if (login != null && mdp != null) { |
|
654 |
authenticatedURLMode = true; |
|
655 |
} |
|
656 |
else { |
|
657 |
authenticatedURLMode = false; |
|
658 |
} |
|
659 |
} |
|
597 | 660 |
} |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/editors/vlcplayer/JFXPlayer.java (revision 2445) | ||
---|---|---|
1 |
package org.txm.backtomedia.editors.vlcplayer; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.net.Authenticator; |
|
5 |
import java.net.PasswordAuthentication; |
|
6 |
import java.time.LocalTime; |
|
7 |
import java.time.format.DateTimeFormatter; |
|
8 |
import java.util.concurrent.Semaphore; |
|
9 |
|
|
10 |
import org.eclipse.swt.SWT; |
|
11 |
import org.eclipse.swt.events.DisposeEvent; |
|
12 |
import org.eclipse.swt.events.DisposeListener; |
|
13 |
import org.eclipse.swt.events.MouseEvent; |
|
14 |
import org.eclipse.swt.events.MouseListener; |
|
15 |
import org.eclipse.swt.events.SelectionEvent; |
|
16 |
import org.eclipse.swt.events.SelectionListener; |
|
17 |
import org.eclipse.swt.graphics.Point; |
|
18 |
import org.eclipse.swt.layout.GridData; |
|
19 |
import org.eclipse.swt.layout.GridLayout; |
|
20 |
import org.eclipse.swt.widgets.Button; |
|
21 |
import org.eclipse.swt.widgets.Composite; |
|
22 |
import org.eclipse.swt.widgets.Event; |
|
23 |
import org.eclipse.swt.widgets.FileDialog; |
|
24 |
import org.eclipse.swt.widgets.Label; |
|
25 |
import org.eclipse.swt.widgets.Listener; |
|
26 |
import org.eclipse.swt.widgets.Scale; |
|
27 |
import org.txm.backtomedia.commands.function.TripleRangeSlider; |
|
28 |
import org.txm.backtomedia.preferences.BackToMediaPreferences; |
|
29 |
import org.txm.rcp.swt.GLComposite; |
|
30 |
import org.txm.utils.logger.Log; |
|
31 |
|
|
32 |
import javafx.beans.InvalidationListener; |
|
33 |
import javafx.beans.Observable; |
|
34 |
import javafx.embed.swt.FXCanvas; |
|
35 |
import javafx.scene.Group; |
|
36 |
import javafx.scene.Scene; |
|
37 |
import javafx.scene.media.Media; |
|
38 |
import javafx.scene.media.MediaPlayer; |
|
39 |
import javafx.scene.media.MediaPlayer.Status; |
|
40 |
import javafx.scene.media.MediaView; |
|
41 |
import javafx.scene.paint.Color; |
|
42 |
import javafx.util.Duration; |
|
43 |
import vlcplayerrcp.MessagesMP; |
|
44 |
|
|
45 |
public class JFXPlayer extends Composite implements IPlayer { |
|
46 |
|
|
47 |
protected static final String NOMEDIA = ""; //$NON-NLS-1$ |
|
48 |
|
|
49 |
private MediaPlayer vlcPlayer; |
|
50 |
|
|
51 |
private GLComposite videoComposite; |
|
52 |
|
|
53 |
private Scale rateField; |
|
54 |
|
|
55 |
private Label rateValueLabel; |
|
56 |
|
|
57 |
private Scale volumeField; |
|
58 |
|
|
59 |
private Label volumeValueLabel; |
|
60 |
|
|
61 |
private Button playButton; |
|
62 |
|
|
63 |
private Button repeatButton; |
|
64 |
|
|
65 |
protected String currentlyPlayed = ""; //$NON-NLS-1$ |
|
66 |
|
|
67 |
// private String startTime, endTime; |
|
68 |
private int start, end; |
|
69 |
|
|
70 |
protected boolean hasEnded = false; |
|
71 |
|
|
72 |
private String previouslyPlayed = ""; //$NON-NLS-1$ |
|
73 |
|
|
74 |
private boolean repeat = false; |
|
75 |
|
|
76 |
protected int volume = 100; |
|
77 |
|
|
78 |
private Button stopButton; |
|
79 |
|
|
80 |
Label timeLabel; |
|
81 |
|
|
82 |
TripleRangeSlider timeRange; |
|
83 |
|
|
84 |
boolean firstLengthEvent = true; |
|
85 |
|
|
86 |
long previous = 0; |
|
87 |
|
|
88 |
long time, mins, secs; |
|
89 |
|
|
90 |
public MediaPlayer getEmbeddedMediaPlayer() { |
|
91 |
return vlcPlayer; |
|
92 |
} |
|
93 |
|
|
94 |
Semaphore s = new Semaphore(1); |
|
95 |
|
|
96 |
private FXCanvas fxCanvas; |
|
97 |
|
|
98 |
Point previousP; |
|
99 |
|
|
100 |
protected boolean userStopped; |
|
101 |
|
|
102 |
public JFXPlayer(Composite parent, int style) { |
|
103 |
super(parent, style); |
|
104 |
this.setLayout(new GridLayout(11, false)); |
|
105 |
|
|
106 |
// THE PLAYER |
|
107 |
// if (RuntimeUtil.isMac()) { |
|
108 |
// try { |
|
109 |
// LibC.INSTANCE.setenv("VLC_PLUGIN_PATH", "/Applications/VLC.app/Contents/MacOS/plugins", 1); |
|
110 |
// } |
|
111 |
// catch (Exception ex) { |
|
112 |
// ex.printStackTrace(); |
|
113 |
// } |
|
114 |
// } |
|
115 |
videoComposite = new GLComposite(this, SWT.NONE, "Video"); |
|
116 |
GridData gdata = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
117 |
gdata.horizontalSpan = 11; |
|
118 |
videoComposite.setLayoutData(gdata); |
|
119 |
vlcPlayer = null; |
|
120 |
|
|
121 |
videoComposite.addDisposeListener(new DisposeListener() { |
|
122 |
|
|
123 |
@Override |
|
124 |
public void widgetDisposed(DisposeEvent e) { |
|
125 |
if (vlcPlayer != null) { |
|
126 |
vlcPlayer.dispose(); |
|
127 |
vlcPlayer = null; |
|
128 |
fxCanvas.setScene(null); |
|
129 |
} |
|
130 |
} |
|
131 |
}); |
|
132 |
|
|
133 |
fxCanvas = new FXCanvas(videoComposite, SWT.BORDER); |
|
134 |
GridData gdata2 = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
135 |
fxCanvas.setLayoutData(gdata2); |
|
136 |
|
|
137 |
fxCanvas.addMouseListener(new MouseListener() { |
|
138 |
|
|
139 |
@Override |
|
140 |
public void mouseUp(MouseEvent e) { |
|
141 |
if (vlcPlayer != null) { |
|
142 |
if (vlcPlayer.getStatus().equals(Status.PAUSED)) { |
|
143 |
resume(); |
|
144 |
} |
|
145 |
else if (vlcPlayer.getStatus().equals(Status.PLAYING)) { |
|
146 |
pause(); |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
@Override |
|
152 |
public void mouseDown(MouseEvent e) {} |
|
153 |
|
|
154 |
@Override |
|
155 |
public void mouseDoubleClick(MouseEvent e) {} |
|
156 |
}); |
|
157 |
|
|
158 |
videoComposite.addListener(SWT.Resize, new Listener() { |
|
159 |
|
|
160 |
@Override |
|
161 |
public void handleEvent(Event e) { |
|
162 |
resizeView(); |
|
163 |
} |
|
164 |
}); |
|
165 |
|
|
166 |
// THE CONTROL BUTTONS |
|
167 |
playButton = new Button(this, SWT.PUSH); |
|
168 |
GridData playLayoutData = new GridData(SWT.FILL, SWT.CENTER, false, false); |
|
169 |
playButton.setLayoutData(playLayoutData); |
|
170 |
playButton.setText(MessagesMP.play); |
|
171 |
playButton.addSelectionListener(new SelectionListener() { |
|
172 |
|
|
173 |
@Override |
|
174 |
public void widgetSelected(SelectionEvent e) { |
|
175 |
userStopped = false; |
|
176 |
if (currentlyPlayed.length() == 0) { |
|
177 |
selectMedia(); |
|
178 |
playButton.setText(MessagesMP.pause); |
|
179 |
} |
|
180 |
else if (vlcPlayer != null && vlcPlayer.getStatus().equals(Status.PLAYING)) { |
|
181 |
pause(); |
|
182 |
} |
|
183 |
else if (vlcPlayer != null && hasEnded) { |
|
184 |
if (vlcPlayer == null) return; |
|
185 |
replay(); |
|
186 |
} |
|
187 |
else { |
|
188 |
resume(); |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
@Override |
|
193 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
194 |
}); |
|
195 |
|
|
196 |
// Button browseButton = new Button(this,SWT.PUSH); |
|
197 |
// browseButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); |
|
198 |
// browseButton.setText("Open..."); |
|
199 |
// browseButton.addSelectionListener(new SelectionListener() { |
|
200 |
// @Override |
|
201 |
// public void widgetSelected(SelectionEvent e) { |
|
202 |
// selectMedia(); |
|
203 |
// } |
|
204 |
// |
|
205 |
// @Override |
|
206 |
// public void widgetDefaultSelected(SelectionEvent e) {} |
|
207 |
// }); |
|
208 |
|
|
209 |
stopButton = new Button(this, SWT.PUSH); |
|
210 |
stopButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); |
|
211 |
stopButton.setText(MessagesMP.stop); |
|
212 |
stopButton.addSelectionListener(new SelectionListener() { |
|
213 |
|
|
214 |
@Override |
|
215 |
public void widgetSelected(SelectionEvent e) { |
|
216 |
if (vlcPlayer != null) { |
|
217 |
userStopped = true; |
|
218 |
vlcPlayer.stop(); |
|
219 |
} |
|
220 |
} |
|
221 |
|
|
222 |
@Override |
|
223 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
224 |
}); |
|
225 |
|
|
226 |
timeLabel = new Label(this, SWT.NONE); |
|
227 |
timeLabel.setText("00:00"); //$NON-NLS-1$ |
|
228 |
|
|
229 |
timeRange = new TripleRangeSlider(this, SWT.None); |
|
230 |
timeRange.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
|
231 |
timeRange.setToolTipText(MessagesMP.time_range); |
|
232 |
timeRange.addSelectionListener(new SelectionListener() { |
|
233 |
|
|
234 |
@Override |
|
235 |
public void widgetSelected(SelectionEvent e) { |
|
236 |
TripleRangeSlider.SELECTED_KNOB sk = timeRange.getLastSelectedKnob(); |
|
237 |
switch (sk) { |
|
238 |
case UPPER: |
|
239 |
end = timeRange.getUpperValue(); |
|
240 |
|
|
241 |
vlcPlayer.setStopTime(Duration.seconds(end)); |
|
242 |
if (end < time) { |
|
243 |
// System.out.println("Upper changed: fix time"); |
|
244 |
time = end; |
|
245 |
vlcPlayer.seek(Duration.seconds(time)); |
|
246 |
} |
|
247 |
break; |
|
248 |
case LOWER: |
|
249 |
start = timeRange.getLowerValue(); |
|
250 |
vlcPlayer.setStartTime(Duration.seconds(start)); |
|
251 |
if (start > time) { |
|
252 |
// System.out.println("Lower changed: fix time"); |
|
253 |
time = start; |
|
254 |
vlcPlayer.seek(Duration.seconds(time)); |
|
255 |
} |
|
256 |
break; |
|
257 |
case MIDDLE: |
|
258 |
|
|
259 |
time = timeRange.getMiddleValue(); |
|
260 |
// System.out.println("Middle changed: fix time: " + time); |
|
261 |
|
|
262 |
vlcPlayer.seek(Duration.seconds(time)); |
|
263 |
|
|
264 |
break; |
|
265 |
default: |
|
266 |
// nothing |
|
267 |
} |
|
268 |
// System.out.println("time range: "+start+" -> "+end+" time="+time); |
|
269 |
} |
|
270 |
|
|
271 |
@Override |
|
272 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
273 |
}); |
|
274 |
|
|
275 |
repeatButton = new Button(this, SWT.CHECK); |
|
276 |
repeatButton.setText(MessagesMP.repeat); |
|
277 |
repeat = BackToMediaPreferences.getInstance().getBoolean(BackToMediaPreferences.REPEAT); |
|
278 |
repeatButton.setSelection(repeat); |
|
279 |
repeatButton.addSelectionListener(new SelectionListener() { |
|
280 |
|
|
281 |
@Override |
|
282 |
public void widgetSelected(SelectionEvent e) { |
|
283 |
repeat = repeatButton.getSelection(); |
|
284 |
} |
|
285 |
|
|
286 |
@Override |
|
287 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
288 |
}); |
|
289 |
|
|
290 |
Label l = new Label(this, SWT.NONE); |
|
291 |
l.setText(MessagesMP.rate); |
|
292 |
|
|
293 |
rateField = new Scale(this, SWT.BORDER); |
|
294 |
GridData gdata4 = new GridData(SWT.FILL, SWT.CENTER, false, false); |
|
295 |
gdata4.widthHint = 100; |
|
296 |
rateField.setLayoutData(gdata4); |
|
297 |
rateField.setMaximum(140); |
|
298 |
rateField.setMinimum(70); |
|
299 |
rateField.setSelection(100); |
|
300 |
rateField.setPageIncrement(5); |
|
301 |
|
|
302 |
rateField.addSelectionListener(new SelectionListener() { |
|
303 |
|
|
304 |
@Override |
|
305 |
public void widgetSelected(SelectionEvent e) { |
|
306 |
float rate = rateField.getSelection() / 100.0f; |
|
307 |
vlcPlayer.setRate(rate); |
|
308 |
rateValueLabel.setText("" + rateField.getSelection() + "%"); |
|
309 |
} |
|
310 |
|
|
311 |
@Override |
|
312 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
313 |
}); |
|
314 |
|
|
315 |
rateValueLabel = new Label(this, SWT.NONE); |
|
316 |
rateValueLabel.setText("100%");//$NON-NLS-1$ |
|
317 |
|
|
318 |
l = new Label(this, SWT.NONE); |
|
319 |
l.setText(MessagesMP.volume); |
|
320 |
|
|
321 |
volumeField = new Scale(this, SWT.BORDER); |
|
322 |
gdata4 = new GridData(SWT.FILL, SWT.CENTER, false, false); |
|
323 |
gdata4.widthHint = 100; |
|
324 |
volumeField.setLayoutData(gdata4); |
|
325 |
volumeField.setMinimum(0); |
|
326 |
volumeField.setMaximum(100); |
|
327 |
volumeField.setSelection(volume); |
|
328 |
volumeField.setPageIncrement(5); |
|
329 |
volumeField.addSelectionListener(new SelectionListener() { |
|
330 |
|
|
331 |
@Override |
|
332 |
public void widgetSelected(SelectionEvent e) { |
|
333 |
vlcPlayer.setVolume(volumeField.getSelection()); |
|
334 |
volume = volumeField.getSelection(); |
|
335 |
volumeValueLabel.setText("" + volume + "%"); |
|
336 |
} |
|
337 |
|
|
338 |
@Override |
|
339 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
340 |
}); |
|
341 |
|
|
342 |
volumeValueLabel = new Label(this, SWT.NONE); |
|
343 |
volumeValueLabel.setText("100%"); |
|
344 |
|
|
345 |
// vlcPlayer.events().addMediaPlayerEventListener(new MediaPlayerEventAdapter() { |
|
346 |
// |
|
347 |
// @Override |
|
348 |
// public void opening(MediaPlayer mediaPlayer) { |
|
349 |
// if (videoComposite.isDisposed()) return; |
|
350 |
// Log.finer("Opening media..."); |
|
351 |
// } |
|
352 |
// |
|
353 |
// @Override |
|
354 |
// public void finished(MediaPlayer mediaPlayer) { |
|
355 |
// if (videoComposite.isDisposed()) return; |
|
356 |
// Log.finer("Finished playing media..."); |
|
357 |
// if (repeat) { |
|
358 |
// replay(); |
|
359 |
// } |
|
360 |
// else { |
|
361 |
// hasEnded = true; |
|
362 |
// } |
|
363 |
// } |
|
364 |
// }); |
|
365 |
|
|
366 |
|
|
367 |
// |
|
368 |
// vlcPlayer.events().addMediaPlayerEventListener(new MediaPlayerEventAdapter() { |
|
369 |
// |
|
370 |
// @Override |
|
371 |
// public void timeChanged(MediaPlayer mediaPlayer, final long arg1) { |
|
372 |
// |
|
373 |
// } |
|
374 |
// |
|
375 |
// @Override |
|
376 |
// public void lengthChanged(MediaPlayer mediaPlayer, final long arg1) { |
|
377 |
// if (videoComposite.isDisposed()) return; |
|
378 |
// |
|
379 |
// if (firstLengthEvent) { |
|
380 |
// firstLengthEvent = false; |
|
381 |
// |
|
382 |
// // initialize time range widget limits |
|
383 |
// timeRange.getDisplay().syncExec(new Runnable() { |
|
384 |
// |
|
385 |
// @Override |
|
386 |
// public void run() { |
|
387 |
// if (timeRange.isDisposed()) return; |
|
388 |
// timeRange.setMaximum((int) arg1); |
|
389 |
// // if (start == end) end = (int)arg1; |
|
390 |
// |
|
391 |
// if (end > 0 && start != end) { |
|
392 |
// timeRange.setUpperValue(end); |
|
393 |
// } |
|
394 |
// else { |
|
395 |
// timeRange.setUpperValue((int) arg1); |
|
396 |
// } |
|
397 |
// |
|
398 |
// timeRange.setLowerValue(start); |
|
399 |
// // System.out.println("Range: "+start+" -> "+end+" song length "+arg1); |
|
400 |
// } |
|
401 |
// }); |
|
402 |
// } |
|
403 |
// } |
|
404 |
// }); |
|
405 |
} |
|
406 |
|
|
407 |
protected void resizeView() { |
|
408 |
if (view != null) { |
|
409 |
Point p = videoComposite.getSize(); |
|
410 |
// if (previousP == null || (p.x != previousP.x && p.y != previousP.y)) { // ensure size changed |
|
411 |
view.setFitHeight(p.y); |
|
412 |
view.setFitWidth(p.x); |
|
413 |
previousP = p; |
|
414 |
// } |
|
415 |
} |
|
416 |
} |
|
417 |
|
|
418 |
protected void resume() { |
|
419 |
if (vlcPlayer != null) { |
|
420 |
vlcPlayer.play(); |
|
421 |
playButton.setText(MessagesMP.pause); |
|
422 |
} |
|
423 |
} |
|
424 |
|
|
425 |
protected void pause() { |
|
426 |
if (vlcPlayer != null) { |
|
427 |
vlcPlayer.pause(); |
|
428 |
playButton.setText(MessagesMP.resume); |
|
429 |
} |
|
430 |
} |
|
431 |
|
|
432 |
private void updateTimeLabel() { |
|
433 |
mins = time / 60; |
|
434 |
secs = (time) % 60; |
|
435 |
timeLabel.setText(String.format("%02d:%02d", mins, secs)); //$NON-NLS-1$ |
|
436 |
timeLabel.update(); |
|
437 |
} |
|
438 |
|
|
439 |
protected void replay() { |
|
440 |
if (currentlyPlayed.length() > 0) { |
|
441 |
vlcPlayer.seek(Duration.seconds(start)); |
|
442 |
playButton.setText(MessagesMP.pause); |
|
443 |
} |
|
444 |
} |
|
445 |
|
|
446 |
protected void selectMedia() { |
|
447 |
Log.fine(MessagesMP.select_file); |
|
448 |
|
|
449 |
FileDialog fd = new FileDialog(JFXPlayer.this.getShell(), SWT.OPEN); |
|
450 |
fd.setText(MessagesMP.select_file_title); |
|
451 |
File f = new File(previouslyPlayed); |
|
452 |
if (f.isDirectory()) fd.setFilterPath(f.getPath()); |
|
453 |
else fd.setFilterPath(f.getParent()); |
|
454 |
|
|
455 |
String[] filterExt = { "*.*", "*.mp3", "*.mp4", "*.avi" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
456 |
fd.setFilterExtensions(filterExt); |
|
457 |
String selected = fd.open(); |
|
458 |
if (selected == null) { |
|
459 |
System.out.println(MessagesMP.cancel); |
|
460 |
return; |
|
461 |
} |
|
462 |
|
|
463 |
currentlyPlayed = selected; |
|
464 |
previouslyPlayed = selected; |
|
465 |
Log.fine(MessagesMP.opening + currentlyPlayed); |
|
466 |
play(new File(currentlyPlayed).toURI().toString(), 0, 0); |
|
467 |
} |
|
468 |
|
|
469 |
/** |
|
470 |
* |
|
471 |
* @param mrl |
|
472 |
* @param time msec start time |
|
473 |
* @param endtime msec end time |
|
474 |
*/ |
|
475 |
@Override |
|
476 |
public boolean play(String mrl, int time, int endtime) { |
|
477 |
Log.fine(MessagesMP.bind(MessagesMP.playing, new Object[] { mrl, time, endtime })); |
|
478 |
return play(mrl, "" + time, "" + endtime); //$NON-NLS-1$ //$NON-NLS-2$ |
|
479 |
} |
|
480 |
|
|
481 |
@Override |
|
482 |
public boolean play(String mrl, int time) { |
|
483 |
return play(mrl, time, time); |
|
484 |
} |
|
485 |
|
|
486 |
public void hideStopButton() { |
|
487 |
if (this.stopButton != null && !this.stopButton.isDisposed()) { |
|
488 |
this.stopButton.dispose(); |
|
489 |
} |
|
490 |
} |
|
491 |
|
|
492 |
DateTimeFormatter hhmmssFormatter = DateTimeFormatter.ISO_LOCAL_TIME; |
|
493 |
|
|
494 |
private MediaView view; |
|
495 |
|
|
496 |
private Group group; |
|
497 |
|
|
498 |
private Scene scene; |
|
499 |
|
|
500 |
private String mrl; |
|
501 |
|
|
502 |
private Media media; |
|
503 |
|
|
504 |
@Override |
|
505 |
public final void setCredentials(String login, String mdp) { |
|
506 |
Authenticator.setDefault(new Authenticator() { |
|
507 |
|
|
508 |
@Override |
|
509 |
public PasswordAuthentication getPasswordAuthentication() { |
|
510 |
// System.out.println("PA: login=" + login + " mdp=" + mdp + " mrl=" + mrl + " req=" + getRequestingHost()); |
|
511 |
if (login != null && mdp != null && mrl.contains("://" + getRequestingHost() + "/")) { |
|
512 |
return new PasswordAuthentication(login, mdp.toCharArray()); |
|
513 |
} |
|
514 |
return null; |
|
515 |
} |
|
516 |
}); |
|
517 |
} |
|
518 |
|
|
519 |
/** |
|
520 |
* |
|
521 |
* @param mrl |
|
522 |
* @param startTime "0.0" or ""hh:mm:ss" format |
|
523 |
* @param endTime "0.0" or ""hh:mm:ss" format |
|
524 |
*/ |
|
525 |
@Override |
|
526 |
public boolean play(String mrl, String startTime, String endTime) { |
|
527 |
|
|
528 |
if (mrl.contains("{0}:{1}@")) { |
|
529 |
mrl = mrl.replace("{0}:{1}@", ""); |
|
530 |
} |
|
531 |
|
|
532 |
this.mrl = mrl; |
|
533 |
if (startTime.matches("[0-9]+.[0-9]+")) { |
|
534 |
start = (int) (Float.parseFloat(startTime)); |
|
535 |
} |
|
536 |
else if (startTime.matches("[0-9]+:[0-9]+:[0-9]+")) { |
|
537 |
if (startTime.indexOf(":") == 1) { |
|
538 |
startTime = "0" + startTime; |
|
539 |
} |
|
540 |
LocalTime time1 = LocalTime.parse(startTime, hhmmssFormatter); |
|
541 |
start = ((time1.getHour() * 60 * 60) + (time1.getMinute() * 60) + time1.getSecond()); |
|
542 |
} |
|
543 |
|
|
544 |
if (endTime.matches("[0-9]+.[0-9]+")) { |
|
545 |
end = (int) (Float.parseFloat(endTime)); |
|
546 |
} |
|
547 |
else if (endTime.matches("[0-9]+:[0-9]+:[0-9]+")) { |
|
548 |
if (endTime.indexOf(":") == 1) endTime = "0" + endTime; |
|
549 |
LocalTime time1 = LocalTime.parse(endTime, hhmmssFormatter); |
|
550 |
end = ((time1.getHour() * 60 * 60) + (time1.getMinute() * 60) + time1.getSecond()); |
|
551 |
} |
|
552 |
|
|
553 |
// if (start == end) end = -1; |
|
554 |
|
|
555 |
Log.finer(MessagesMP.bind(MessagesMP.playing, new Object[] { mrl, startTime, endTime })); |
|
556 |
// vlcPlayer.submit(new Runnable() { |
|
557 |
// |
|
558 |
// @Override |
|
559 |
// public void run() { |
|
560 |
// String[] options = { " :live-caching=200" }; // reduce video stream cache duration to 200ms |
|
561 |
|
|
562 |
Log.finer("Preparing media..."); |
|
563 |
try { |
|
564 |
javafx.application.Platform.setImplicitExit(false); |
|
565 |
javafx.application.Platform.runLater(new Runnable() { |
|
566 |
|
|
567 |
@Override |
|
568 |
public void run() { |
|
569 |
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { |
|
570 |
|
|
571 |
@Override |
|
572 |
public void uncaughtException(Thread t, Throwable e) { |
|
573 |
System.out.println("JavaFX uncaught exception: " + e); |
|
574 |
} |
|
575 |
}); |
|
576 |
} |
|
577 |
}); |
|
578 |
media = new Media(mrl); |
|
579 |
vlcPlayer = new MediaPlayer(media); |
|
580 |
|
|
581 |
if (vlcPlayer.getError() == null) { |
|
582 |
vlcPlayer.setOnError(new Runnable() { |
|
583 |
|
|
584 |
@Override |
|
585 |
public void run() { |
|
586 |
vlcPlayer.getError().printStackTrace(); |
|
587 |
} |
|
588 |
}); |
|
589 |
} |
|
590 |
else { |
|
591 |
System.out.println("Warning: could not retrieve media error logger"); |
|
592 |
} |
|
593 |
|
|
594 |
initializePlayerListeners(); |
|
595 |
vlcPlayer.setAutoPlay(false); |
|
596 |
|
|
597 |
view = new MediaView(vlcPlayer); |
|
598 |
|
|
599 |
group = new Group(view); |
|
600 |
|
|
601 |
// scene = new Scene(group, Color.rgb(fxCanvas.getBackground().getRed(), fxCanvas.getBackground().getGreen(), fxCanvas.getBackground().getBlue())); |
|
602 |
scene = new Scene(group, Color.rgb(0, 0, 0)); |
|
603 |
|
|
604 |
fxCanvas.setScene(scene); |
|
605 |
|
|
606 |
view.setPreserveRatio(true); |
|
607 |
} |
|
608 |
catch (Exception e) { |
|
609 |
e.printStackTrace(); |
|
610 |
return false; |
|
611 |
} |
|
612 |
|
|
613 |
vlcPlayer.setOnReady(new Runnable() { |
|
614 |
|
|
615 |
@Override |
|
616 |
public void run() { |
|
617 |
|
|
618 |
timeRange.setMinimum(0); |
|
619 |
Duration d = vlcPlayer.getMedia().getDuration(); |
|
620 |
if (d.toSeconds() > 0) { |
|
621 |
timeRange.setMaximum((int) d.toSeconds()); |
|
622 |
} |
|
623 |
timeRange.setLowerValue(start); |
|
624 |
timeRange.setMiddleValue(start); |
|
625 |
|
|
626 |
System.out.println("start=" + start + " end=" + end); |
|
627 |
vlcPlayer.setVolume(volume); |
|
628 |
System.out.println("SEEK " + start + " D=" + Duration.seconds(start)); |
|
629 |
|
|
630 |
vlcPlayer.setStartTime(Duration.seconds(start)); |
|
631 |
vlcPlayer.seek(Duration.seconds(start)); |
|
632 |
if (end > start) { |
|
633 |
timeRange.setUpperValue(end); |
|
634 |
vlcPlayer.setStopTime(Duration.seconds(end)); |
|
635 |
} |
|
636 |
else if (d.toSeconds() > 0) { |
|
637 |
System.out.println("end=length=" + d.toSeconds()); |
|
638 |
timeRange.setUpperValue((int) vlcPlayer.getMedia().getDuration().toSeconds()); |
|
639 |
} |
|
640 |
Log.info("Playing media..."); |
|
641 |
|
|
642 |
vlcPlayer.play(); |
|
643 |
resizeView(); |
|
644 |
|
|
645 |
// if (new File(mrl + ".srt").exists()) { //$NON-NLS-1$ |
|
646 |
// vlcPlayer.sub.subpictures().setSubTitleFile(mrl + ".srt"); //$NON-NLS-1$ |
|
647 |
// } |
|
648 |
currentlyPlayed = JFXPlayer.this.mrl; |
|
649 |
previouslyPlayed = JFXPlayer.this.mrl; |
|
650 |
|
|
651 |
if (!playButton.isDisposed()) { |
|
652 |
playButton.setText(MessagesMP.pause); |
|
653 |
} |
|
654 |
firstLengthEvent = true; |
|
655 |
// } |
|
656 |
// }); |
|
657 |
} |
|
658 |
}); |
|
659 |
|
|
660 |
|
|
661 |
|
|
662 |
return true; |
|
663 |
} |
|
664 |
|
|
665 |
private void initializePlayerListeners() { |
|
666 |
|
|
667 |
vlcPlayer.currentTimeProperty().addListener(new InvalidationListener() { |
|
668 |
|
|
669 |
@Override |
|
670 |
public void invalidated(Observable ov) { |
|
671 |
if (videoComposite.isDisposed()) return; |
|
672 |
if (vlcPlayer == null) return; |
|
673 |
|
|
674 |
Duration currentTime = vlcPlayer.getCurrentTime(); |
|
675 |
time = (int) currentTime.toSeconds(); |
|
676 |
if (previous == time) { |
|
677 |
return; |
|
678 |
} |
|
679 |
previous = time; |
|
680 |
|
|
681 |
timeLabel.getDisplay().syncExec(new Runnable() { |
|
682 |
|
|
683 |
@Override |
|
684 |
public void run() { |
|
685 |
if (timeRange.isDisposed()) { |
|
686 |
return; |
|
687 |
} |
|
688 |
if (!timeRange.isDragMiddleKnob()) { |
|
689 |
timeRange.setMiddleValue((int) time); |
|
690 |
} |
|
691 |
updateTimeLabel(); |
|
692 |
|
|
693 |
// if (time >= end && end != start) { |
|
694 |
// if (repeat) { |
|
695 |
// vlcPlayer.seek(Duration.seconds(start)); |
|
696 |
// } |
|
697 |
// else { |
|
698 |
// vlcPlayer.stop(); |
|
699 |
// } |
|
700 |
// } |
|
701 |
} |
|
702 |
}); |
|
703 |
} |
|
704 |
}); |
|
705 |
} |
|
706 |
|
|
707 |
@Override |
|
708 |
public void setRepeat(boolean repeat) { |
|
709 |
this.repeat = repeat; |
|
710 |
if (this.repeat) { |
|
711 |
vlcPlayer.setCycleCount(Integer.MAX_VALUE); |
|
712 |
} |
|
713 |
else { |
|
714 |
vlcPlayer.setCycleCount(0); |
|
715 |
} |
|
716 |
if (!repeatButton.isDisposed()) { |
|
717 |
repeatButton.setSelection(repeat); |
|
718 |
} |
|
719 |
} |
|
720 |
|
|
721 |
@Override |
|
722 |
public void stop() { |
|
723 |
if (vlcPlayer == null) return; // nothing to do |
|
724 |
userStopped = true; |
|
725 |
vlcPlayer.stop(); |
|
726 |
|
|
727 |
vlcPlayer.dispose(); |
|
728 |
vlcPlayer = null; |
|
729 |
fxCanvas.setScene(null); |
|
730 |
|
|
731 |
currentlyPlayed = NOMEDIA; |
|
732 |
if (!playButton.isDisposed()) { |
|
733 |
playButton.setText(MessagesMP.play); |
|
734 |
} |
|
735 |
} |
|
736 |
|
|
737 |
@Override |
|
738 |
public boolean isMediaLoaded() { |
|
739 |
return vlcPlayer != null && vlcPlayer.getStatus().equals(Status.READY); |
|
740 |
} |
|
741 |
} |
|
0 | 742 |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/editors/vlcplayer/IPlayer.java (revision 2445) | ||
---|---|---|
1 |
package org.txm.backtomedia.editors.vlcplayer; |
|
2 |
|
|
3 |
|
|
4 |
public interface IPlayer { |
|
5 |
|
|
6 |
public void setCredentials(String login, String mdp); |
|
7 |
|
|
8 |
public boolean play(String mrl, String start, String end); |
|
9 |
|
|
10 |
public boolean play(String mrl, int start, int end); |
|
11 |
|
|
12 |
public boolean play(String mrl, int start); |
|
13 |
|
|
14 |
public void stop(); |
|
15 |
|
|
16 |
public boolean isMediaLoaded(); |
|
17 |
|
|
18 |
public void setRepeat(boolean b); |
|
19 |
|
|
20 |
public boolean isDisposed(); |
|
21 |
} |
|
0 | 22 |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/editors/vlcplayer/VLCPlayerEditor.java (revision 2445) | ||
---|---|---|
7 | 7 |
import org.eclipse.ui.IEditorSite; |
8 | 8 |
import org.eclipse.ui.PartInitException; |
9 | 9 |
import org.eclipse.ui.part.EditorPart; |
10 |
import org.txm.backtomedia.commands.function.MediaPreferences; |
|
11 |
import org.txm.backtomedia.preferences.BackToMediaPreferences; |
|
10 | 12 |
|
11 | 13 |
public class VLCPlayerEditor extends EditorPart { |
12 | 14 |
|
13 | 15 |
/** The Constant ID. */ |
14 | 16 |
public static final String ID = VLCPlayerEditor.class.getCanonicalName(); // $NON-NLS-1$ |
15 | 17 |
|
16 |
VLCPlayer player;
|
|
18 |
IPlayer player;
|
|
17 | 19 |
|
18 | 20 |
@Override |
19 | 21 |
public void createPartControl(Composite parent) { |
20 |
player = new VLCPlayer(parent, SWT.NONE); |
|
22 |
if ("JFX".equals(BackToMediaPreferences.getInstance().getString(BackToMediaPreferences.PLAYER))) { |
|
23 |
player = new JFXPlayer(parent, SWT.NONE); |
|
24 |
} |
|
25 |
else if ("VLC".equals(BackToMediaPreferences.getInstance().getString(BackToMediaPreferences.PLAYER))) { |
|
26 |
player = new VLCPlayer(parent, SWT.NONE); |
|
27 |
} |
|
28 |
else { |
|
29 |
player = new JFXPlayer(parent, SWT.NONE); |
|
30 |
} |
|
21 | 31 |
} |
22 | 32 |
|
23 | 33 |
public void init() { |
... | ... | |
76 | 86 |
return false; |
77 | 87 |
} |
78 | 88 |
|
79 |
public VLCPlayer getPlayer() {
|
|
89 |
public IPlayer getPlayer() {
|
|
80 | 90 |
return player; |
81 | 91 |
} |
82 | 92 |
|
93 |
@Override |
|
83 | 94 |
public void setPartName(String partName) { |
84 | 95 |
super.setPartName(partName); |
85 | 96 |
} |
... | ... | |
95 | 106 |
* @return false if the media could not be loaded (file not found, access error...) |
96 | 107 |
*/ |
97 | 108 |
public boolean isMediaLoaded() { |
98 |
return player.getEmbeddedMediaPlayer().status().isPlayable();
|
|
109 |
return player.isMediaLoaded();
|
|
99 | 110 |
} |
100 | 111 |
} |
tmp/org.txm.backtomedia.rcp/META-INF/MANIFEST.MF (revision 2445) | ||
---|---|---|
26 | 26 |
uk.co.caprica.vlcj.factory.swt, |
27 | 27 |
uk.co.caprica.vlcj.player.embedded.videosurface.swt, |
28 | 28 |
vlcplayerrcp |
29 |
Import-Package: com.sun.javafx, |
|
30 |
com.sun.javafx.animation, |
|
31 |
com.sun.javafx.applet, |
|
32 |
com.sun.javafx.application, |
|
33 |
com.sun.javafx.beans, |
|
34 |
com.sun.javafx.beans.event, |
|
35 |
com.sun.javafx.binding, |
|
36 |
com.sun.javafx.charts, |
|
37 |
com.sun.javafx.collections, |
|
38 |
com.sun.javafx.css, |
|
39 |
com.sun.javafx.css.converters, |
|
40 |
com.sun.javafx.css.parser, |
|
41 |
com.sun.javafx.cursor, |
|
42 |
com.sun.javafx.effect, |
|
43 |
com.sun.javafx.embed, |
|
44 |
com.sun.javafx.embed.swing, |
|
45 |
com.sun.javafx.event, |
|
46 |
com.sun.javafx.font, |
|
47 |
com.sun.javafx.font.coretext, |
|
48 |
com.sun.javafx.font.directwrite, |
|
49 |
com.sun.javafx.font.freetype, |
|
50 |
com.sun.javafx.font.t2k, |
|
51 |
com.sun.javafx.fxml, |
|
52 |
com.sun.javafx.fxml.builder, |
|
53 |
com.sun.javafx.fxml.expression, |
|
54 |
com.sun.javafx.geom, |
|
55 |
com.sun.javafx.geom.transform, |
|
56 |
com.sun.javafx.geometry, |
|
57 |
com.sun.javafx.iio, |
|
58 |
com.sun.javafx.iio.bmp, |
|
59 |
com.sun.javafx.iio.common, |
|
60 |
com.sun.javafx.iio.gif, |
|
61 |
com.sun.javafx.iio.ios, |
|
62 |
com.sun.javafx.iio.jpeg, |
|
63 |
com.sun.javafx.iio.png, |
|
64 |
com.sun.javafx.image, |
|
65 |
com.sun.javafx.image.impl, |
|
66 |
com.sun.javafx.jmx, |
|
67 |
com.sun.javafx.logging, |
|
68 |
com.sun.javafx.media, |
|
69 |
com.sun.javafx.menu, |
|
70 |
com.sun.javafx.perf, |
|
71 |
com.sun.javafx.print, |
|
72 |
com.sun.javafx.property, |
|
73 |
com.sun.javafx.property.adapter, |
|
74 |
com.sun.javafx.robot, |
|
75 |
com.sun.javafx.robot.impl, |
|
76 |
com.sun.javafx.runtime, |
|
77 |
com.sun.javafx.runtime.async, |
|
78 |
com.sun.javafx.runtime.eula, |
|
79 |
com.sun.javafx.scene, |
|
80 |
com.sun.javafx.scene.control, |
|
81 |
com.sun.javafx.scene.control.behavior, |
|
82 |
com.sun.javafx.scene.control.skin, |
|
83 |
com.sun.javafx.scene.control.skin.caspian, |
|
84 |
com.sun.javafx.scene.control.skin.caspian.images, |
|
85 |
com.sun.javafx.scene.control.skin.modena, |
|
86 |
com.sun.javafx.scene.control.skin.resources, |
|
87 |
com.sun.javafx.scene.input, |
|
88 |
com.sun.javafx.scene.layout.region, |
|
89 |
com.sun.javafx.scene.paint, |
|
90 |
com.sun.javafx.scene.shape, |
|
91 |
com.sun.javafx.scene.text, |
|
92 |
com.sun.javafx.scene.transform, |
|
93 |
com.sun.javafx.scene.traversal, |
|
94 |
com.sun.javafx.scene.web, |
|
95 |
com.sun.javafx.scene.web.behavior, |
|
96 |
com.sun.javafx.scene.web.skin, |
|
97 |
com.sun.javafx.sg.prism, |
|
98 |
com.sun.javafx.sg.prism.web, |
|
99 |
com.sun.javafx.stage, |
|
100 |
com.sun.javafx.text, |
|
101 |
com.sun.javafx.tk, |
|
102 |
com.sun.javafx.tk.quantum, |
|
103 |
com.sun.javafx.util, |
|
104 |
com.sun.javafx.webkit, |
|
105 |
com.sun.javafx.webkit.prism, |
|
106 |
com.sun.javafx.webkit.prism.resources, |
|
107 |
com.sun.javafx.webkit.prism.theme, |
|
108 |
com.sun.javafx.webkit.theme, |
|
109 |
javafx.animation, |
|
110 |
javafx.application, |
|
111 |
javafx.beans, |
|
112 |
javafx.beans.binding, |
|
113 |
javafx.beans.property, |
|
114 |
javafx.beans.property.adapter, |
|
115 |
javafx.beans.value, |
|
116 |
javafx.collections, |
|
117 |
javafx.collections.transformation, |
|
118 |
javafx.concurrent, |
|
119 |
javafx.css, |
|
120 |
javafx.embed.swing, |
|
121 |
javafx.embed.swt, |
|
122 |
javafx.event, |
|
123 |
javafx.fxml, |
|
124 |
javafx.geometry, |
|
125 |
javafx.print, |
|
126 |
javafx.scene, |
|
127 |
javafx.scene.canvas, |
|
128 |
javafx.scene.chart, |
|
129 |
javafx.scene.control, |
|
130 |
javafx.scene.control.cell, |
|
131 |
javafx.scene.effect, |
|
132 |
javafx.scene.image, |
|
133 |
javafx.scene.input, |
|
134 |
javafx.scene.layout, |
|
135 |
javafx.scene.media, |
|
136 |
javafx.scene.paint, |
|
137 |
javafx.scene.shape, |
|
138 |
javafx.scene.text, |
|
139 |
javafx.scene.transform, |
|
140 |
javafx.scene.web, |
|
141 |
javafx.stage, |
|
142 |
javafx.util, |
|
143 |
javafx.util.converter |
|
29 | 144 |
|
tmp/org.txm.backtomedia.feature/feature.xml (revision 2445) | ||
---|---|---|
79 | 79 |
version="0.0.0" |
80 | 80 |
unpack="false"/> |
81 | 81 |
|
82 |
<plugin |
|
83 |
id="org.txm.libs.javafx.linux" |
|
84 |
os="linux" |
|
85 |
download-size="0" |
|
86 |
install-size="0" |
|
87 |
version="0.0.0"/> |
|
88 |
|
|
89 |
<plugin |
|
90 |
id="org.txm.libs.javafx.macosx" |
|
91 |
os="macosx" |
|
92 |
download-size="0" |
|
93 |
install-size="0" |
|
94 |
version="0.0.0"/> |
|
95 |
|
|
96 |
<plugin |
|
97 |
id="org.txm.libs.javafx.win32" |
|
98 |
os="win32" |
|
99 |
download-size="0" |
|
100 |
install-size="0" |
|
101 |
version="0.0.0"/> |
|
102 |
|
|
82 | 103 |
</feature> |
Formats disponibles : Unified diff