可以实现播放暂停,快进快退,下一曲,打开文件,不循环,单曲循环,列表循环,播放列表和播放历史等功能(可以播放视频)
/*主程序*/
package videoplayer;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.io.File;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JSlider;
import javax.swing.SwingWorker;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import com.sun.jna.platform.win32.WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.player.embedded.DefaultAdaptiveRuntimeFullScreenStrategy;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
public class PlayerMain {
static Window frame;
static DefaultListModel dlm= new DefaultListModel();
static DefaultListModel dlm1= new DefaultListModel();
//private static final String NATIVE_LIBRARY_SEARCH_PATH = "D:\\Program Files\\VideoLAN\\VLC\\sdk\\lib";
public static void main(String[] args) {
VideoTime videoTime =new VideoTime() ;
NativeLibrary.addSearchPath(
RuntimeUtil.getLibVlcLibraryName(), "D:\\\\Program Files\\\\VideoLAN\\\\VLC"); //导入的路径是vlc的安装路径
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(),LibVlc.class);
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try{
frame=new Window();
frame.setVisible(true);
dlm.addElement("F:\\迅雷下载\\大侦探皮卡丘.720p.1080p.HD中英双字\\大侦探皮卡丘.mp4");
dlm.addElement("F:\\CloudMusic\\梦飞船 - 不值得.flac");
dlm.addElement("F:\\CloudMusic\\Crazy Up!.mp3");
dlm.addElement("F:\\\\CloudMusic\\\\Right Now.mp3");
frame.getList().setModel(dlm);
new SwingWorker<String, Integer>() {
@Override
protected String doInBackground() throws Exception {
// TODO Auto-generated method stub
while (true) { //获取视频播放进度并且按百分比显示
long total=frame.getMediaPlayer().getLength();
long curr=frame.getMediaPlayer().getTime();
//System.out.println(total+" "+curr);
videoTime.timeCalculate(total, curr);
String string1=videoTime.getMinitueCurrent() + ":" + videoTime.getSecondCurrent();
String string2=videoTime.getMinitueTotal() + ":" + videoTime.getSecondTotal();
frame.getCurrentLabel().setText(string1);
frame.getTotalLabel().setText(string2);
float percent=(float)curr/total;
publish((int)(percent*100));
Thread.sleep(200);
if(frame.c==2) {
if (curr==-1&&total==-1) {
frame.Next();
}
}else if (frame.c==1) {
if (curr==-1&&total==-1) {
frame.OneCircu();
}
}{
}
}
}
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 openVideo() {
JFileChooser chooser=new JFileChooser();
int v=chooser.showOpenDialog(null);
if(v==JFileChooser.APPROVE_OPTION){
File file=chooser.getSelectedFile();
String playname=file.getName();
dlm.addElement(file.getAbsoluteFile());
frame.getList().setModel(dlm);
frame.getMediaPlayer().pla