-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayMain.java
More file actions
113 lines (94 loc) · 3.11 KB
/
PlayMain.java
File metadata and controls
113 lines (94 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.jikexueyuan.videoplayer.main;
import java.awt.EventQueue;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.SwingWorker;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import com.jikexueyuan.videoplayer.views.MainWindow;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
public class PlayMain {
static MainWindow frame;
public static void main(String[] args) {
if (RuntimeUtil.isMac()) {
NativeLibrary.addSearchPath(
RuntimeUtil.getLibVlcLibraryName(), "/Applications/VLC.app/Contents/MacOS/lib"
);
}else if (RuntimeUtil.isWindows()) {
NativeLibrary.addSearchPath(
RuntimeUtil.getLibVlcLibraryName(), "C:\\Programe Files\\VideoLan\\vlc\\lib"
);
}else if (RuntimeUtil.isNix()) {
NativeLibrary.addSearchPath(
RuntimeUtil.getLibVlcLibraryName(), "/home/linux/vlc/install/lib"
);
}
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frame = new MainWindow();
frame.setVisible(true);
String options[] = {"--subsdec-encoding=GB18030"};
frame.getMediaPlayer().prepareMedia("/Users/acely/Movies/BBC Earth.The.Biography/Earth.The.Biography.UNRATED.Ep04.2007.BluRay.720p.x264.DTS-WiKi.chs.mkv",options);
// frame.getMediaPlayer().playMedia("/Users/acely/Movies/BBC Earth.The.Biography/Earth.The.Biography.UNRATED.Ep04.2007.BluRay.720p.x264.DTS-WiKi.chs.mkv",options);
new SwingWorker<String, Integer>() {
@Override
protected String doInBackground() throws Exception {
while (true) {
long total = frame.getMediaPlayer().getLength();
long curr = frame.getMediaPlayer().getTime();
float percent = (float)curr/total;
publish((int)(percent*100));
Thread.sleep(100);
}
}
protected void process(java.util.List<Integer> chunks) {
for (int v : chunks) {
frame.getProgressBar().setValue(v);
}
};
}.execute();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public static void play() {
frame.getMediaPlayer().play();
}
public static void pause() {
frame.getMediaPlayer().pause();
}
public static void stop() {
frame.getMediaPlayer().stop();
}
public static void jumpTo(float to) {
frame.getMediaPlayer().setTime((long)(to*frame.getMediaPlayer().getLength()));
}
public static void setVol(int v) {
frame.getMediaPlayer().setVolume(v);
}
public static void openVideo() {
JFileChooser chooser = new JFileChooser();
int v = chooser.showOpenDialog(null);
if (v == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
frame.getMediaPlayer().playMedia(file.getAbsolutePath());
}
}
public static void openSubtitle() {
JFileChooser chooser = new JFileChooser();
int v = chooser.showOpenDialog(null);
if (v == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
frame.getMediaPlayer().setSubTitleFile(file);
}
}
public static void exit() {
frame.getMediaPlayer().release();
System.exit(0);
}
}