基本信息
源码名称:Java视频播放器源码下载
源码大小:6.17M
文件格式:.rar
开发语言:Java
更新时间:2015-08-07
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.qianghui.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.qianghui.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) { // TODO Auto-generated method stub NativeLibrary.addSearchPath( RuntimeUtil.getLibVlcLibraryName(), "D:\\Program Files\\VideoLAN\\VLC" ); 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("D:\\Users\\强辉\\Desktop\\RGB.MP4",options);//传入视频文件路径,播放器参数 //frame.getMediaPlayer().toggleFullScreen(); 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); //每秒循环10次 } } 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 openFile(){ //打开文件 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); } }