1 |
1 |
package org.txm.backtomedia.editors.vlcplayer;
|
2 |
2 |
|
|
3 |
import static uk.co.caprica.vlcj.binding.LibVlc.libvlc_new;
|
|
4 |
import static uk.co.caprica.vlcj.binding.LibVlc.libvlc_release;
|
|
5 |
|
3 |
6 |
import java.io.File;
|
4 |
7 |
import java.time.LocalTime;
|
5 |
8 |
import java.time.format.DateTimeFormatter;
|
6 |
9 |
|
|
10 |
import org.eclipse.osgi.util.NLS;
|
7 |
11 |
import org.eclipse.swt.SWT;
|
|
12 |
import org.eclipse.swt.events.DisposeEvent;
|
|
13 |
import org.eclipse.swt.events.DisposeListener;
|
8 |
14 |
import org.eclipse.swt.events.SelectionEvent;
|
9 |
15 |
import org.eclipse.swt.events.SelectionListener;
|
10 |
16 |
import org.eclipse.swt.layout.GridData;
|
... | ... | |
23 |
29 |
import uk.co.caprica.vlcj.binding.LibC;
|
24 |
30 |
import uk.co.caprica.vlcj.binding.RuntimeUtil;
|
25 |
31 |
import uk.co.caprica.vlcj.binding.internal.libvlc_instance_t;
|
26 |
|
|
27 |
|
import static uk.co.caprica.vlcj.binding.LibVlc.libvlc_new;
|
28 |
|
import static uk.co.caprica.vlcj.binding.LibVlc.libvlc_release;
|
29 |
32 |
import uk.co.caprica.vlcj.factory.discovery.NativeDiscovery;
|
30 |
33 |
import uk.co.caprica.vlcj.factory.discovery.strategy.NativeDiscoveryStrategy;
|
31 |
34 |
import uk.co.caprica.vlcj.factory.swt.SwtMediaPlayerFactory;
|
|
35 |
import uk.co.caprica.vlcj.media.MediaRef;
|
32 |
36 |
import uk.co.caprica.vlcj.player.base.MediaPlayer;
|
33 |
37 |
import uk.co.caprica.vlcj.player.base.MediaPlayerEventAdapter;
|
34 |
38 |
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent;
|
... | ... | |
39 |
43 |
|
40 |
44 |
public class VLCPlayer extends Composite {
|
41 |
45 |
|
42 |
|
static {
|
|
46 |
static { // force native libs discovery -> fix Mac OS X init
|
43 |
47 |
NativeDiscovery discovery = new NativeDiscovery() {
|
44 |
48 |
|
45 |
49 |
@Override
|
... | ... | |
53 |
57 |
}
|
54 |
58 |
};
|
55 |
59 |
boolean found = discovery.discover();
|
56 |
|
System.out.println("VLC NativeDiscovery: " + found);
|
|
60 |
Log.finer("VLC NativeDiscovery: " + found);
|
57 |
61 |
libvlc_instance_t instance = libvlc_new(0, new StringArray(new String[0]));
|
58 |
|
System.out.println("VLC NativeDiscovery: instance " + instance);
|
|
62 |
Log.finer("VLC NativeDiscovery: instance " + instance);
|
59 |
63 |
if (instance != null) {
|
60 |
64 |
libvlc_release(instance);
|
61 |
65 |
}
|
62 |
|
System.out.println("VLC NativeDiscovery: " + new LibVlcVersion().getVersion());
|
|
66 |
Log.finer("VLC NativeDiscovery: " + new LibVlcVersion().getVersion());
|
63 |
67 |
}
|
64 |
68 |
|
65 |
69 |
protected static final String NOMEDIA = ""; //$NON-NLS-1$
|
... | ... | |
124 |
128 |
this.setLayout(new GridLayout(11, false));
|
125 |
129 |
|
126 |
130 |
// THE PLAYER
|
127 |
|
|
128 |
|
if (RuntimeUtil.isMac()) {
|
129 |
|
try {
|
130 |
|
LibC.INSTANCE.setenv("VLC_PLUGIN_PATH", "/Applications/VLC.app/Contents/MacOS/plugins", 1);
|
131 |
|
}
|
132 |
|
catch (Exception ex) {
|
133 |
|
ex.printStackTrace();
|
134 |
|
}
|
135 |
|
}
|
|
131 |
// if (RuntimeUtil.isMac()) {
|
|
132 |
// try {
|
|
133 |
// LibC.INSTANCE.setenv("VLC_PLUGIN_PATH", "/Applications/VLC.app/Contents/MacOS/plugins", 1);
|
|
134 |
// }
|
|
135 |
// catch (Exception ex) {
|
|
136 |
// ex.printStackTrace();
|
|
137 |
// }
|
|
138 |
// }
|
136 |
139 |
videoComposite = new Composite(this, SWT.EMBEDDED | SWT.NO_BACKGROUND);
|
137 |
140 |
GridData gdata = new GridData(SWT.FILL, SWT.FILL, true, true);
|
138 |
141 |
gdata.horizontalSpan = 11;
|
... | ... | |
145 |
148 |
vlcPlayer = e.mediaPlayer();
|
146 |
149 |
vlcPlayer.videoSurface().set(playerCanvas);
|
147 |
150 |
|
148 |
|
// videoComposite.addDisposeListener(new DisposeListener() {
|
149 |
|
// @Override
|
150 |
|
// public void widgetDisposed(DisposeEvent e) {
|
151 |
|
// vlcPlayer.controls().stop();
|
152 |
|
// vlcPlayer.release();
|
153 |
|
// factory.release();
|
154 |
|
// }
|
155 |
|
// });
|
|
151 |
videoComposite.addDisposeListener(new DisposeListener() {
|
|
152 |
|
|
153 |
@Override
|
|
154 |
public void widgetDisposed(DisposeEvent e) {
|
|
155 |
vlcPlayer.controls().stop();
|
|
156 |
vlcPlayer.release();
|
|
157 |
factory.release();
|
|
158 |
}
|
|
159 |
});
|
156 |
160 |
|
157 |
161 |
// THE CONTROL BUTTONS
|
158 |
162 |
playButton = new Button(this, SWT.PUSH);
|
... | ... | |
335 |
339 |
vlcPlayer.events().addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
|
336 |
340 |
|
337 |
341 |
@Override
|
338 |
|
public void playing(MediaPlayer mediaPlayer) {
|
339 |
|
mediaPlayer.submit(new Runnable() {
|
340 |
|
|
341 |
|
@Override
|
342 |
|
public void run() {
|
343 |
|
if (volumeField != null) {
|
344 |
|
vlcPlayer.audio().setVolume(volume);
|
345 |
|
}
|
346 |
|
}
|
347 |
|
});
|
|
342 |
public void opening(MediaPlayer mediaPlayer) {
|
|
343 |
Log.info("Opening media...");
|
348 |
344 |
}
|
349 |
345 |
|
350 |
346 |
@Override
|
... | ... | |
455 |
451 |
protected void replay() {
|
456 |
452 |
if (currentlyPlayed.length() > 0) {
|
457 |
453 |
// this.play(currentlyPlayed, startTime, endTime);
|
458 |
|
vlcPlayer.controls().setTime(start);
|
|
454 |
vlcPlayer.submit(new Runnable() {
|
|
455 |
|
|
456 |
@Override
|
|
457 |
public void run() {
|
|
458 |
vlcPlayer.controls().setTime(start);
|
|
459 |
}
|
|
460 |
});
|
|
461 |
|
459 |
462 |
playButton.setText(MessagesMP.pause);
|
460 |
463 |
}
|
461 |
464 |
}
|
... | ... | |
512 |
515 |
* @param startTime "0.0" or ""hh:mm:ss" format
|
513 |
516 |
* @param endTime "0.0" or ""hh:mm:ss" format
|
514 |
517 |
*/
|
515 |
|
public void play(String mrl, String startTime, String endTime) {
|
|
518 |
public boolean play(String mrl, String startTime, String endTime) {
|
516 |
519 |
|
517 |
520 |
if (startTime.matches("[0-9]+.[0-9]+")) {
|
518 |
521 |
start = (int) (1000 * Float.parseFloat(startTime));
|
... | ... | |
542 |
545 |
// @Override
|
543 |
546 |
// public void run() {
|
544 |
547 |
String[] options = { " :live-caching=200" }; // reduce video stream cache duration to 200ms
|
545 |
|
vlcPlayer.media().play(mrl, options);
|
|
548 |
|
|
549 |
System.out.println("Preparing media...");
|
|
550 |
if (!vlcPlayer.media().prepare(mrl, options)) {
|
|
551 |
return false;
|
|
552 |
}
|
|
553 |
|
|
554 |
System.out.println("Is media valid ?");
|
|
555 |
if (!vlcPlayer.media().isValid()) {
|
|
556 |
return false;
|
|
557 |
}
|
|
558 |
System.out.println("Playing media...");
|
|
559 |
vlcPlayer.controls().play();
|
|
560 |
vlcPlayer.audio().setVolume(volume);
|
546 |
561 |
vlcPlayer.controls().setTime(start);
|
|
562 |
|
547 |
563 |
if (new File(mrl + ".srt").exists()) { //$NON-NLS-1$
|
548 |
564 |
vlcPlayer.subpictures().setSubTitleFile(mrl + ".srt"); //$NON-NLS-1$
|
549 |
565 |
}
|
... | ... | |
554 |
570 |
firstLengthEvent = true;
|
555 |
571 |
// }
|
556 |
572 |
// });
|
|
573 |
return true;
|
557 |
574 |
}
|
558 |
575 |
|
559 |
576 |
public void setRepeat(boolean repeat) {
|