Demo entry 6644199

2

   

Submitted by 2 on Oct 02, 2017 at 09:13
Language: Java. Code size: 2.6 kB.

package 视频播放器;

import java.awt.EventQueue;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.SwingWorker;

import uk.co.caprica.vlcj.discovery.NativeDiscovery;
import video.VideoDir;
import video.VideoService;
import video.VideoServiceService;

public class mainPlay {
	static Window frame;
	private String dirVideo;

	public static void main(String[] args) {

		new NativeDiscovery().discover();

		// 创建主程序界面运行窗体
		EventQueue.invokeLater(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				try {
					frame = new Window();
					//frame.getMediaPlayer().playMedia("src/环保小视频.mp4"); // 控制播放视屏
					new SwingWorker<String, Integer>() {

						protected String doInBackground() throws Exception {
							// TODO Auto-generated method stub
							while (true) { // 获取视频播放进度并且按百分比显示
								long total = frame.getMediaPlayer().getLength();
								long curr = frame.getMediaPlayer().getTime();
								float percent = (float) curr / total;
								publish((int) (percent * 100));
								Thread.sleep(100);
							}
							// return null;
						}

						protected void process(java.util.List<Integer> chunks) {
							for (int v : chunks) {
								frame.getProgerss().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();  
            frame.getMediaPlayer().playMedia(file.getAbsolutePath());  
        }  
    }  
    public static void openVideo(String dir){
    	File file=new File(dir);
    	frame.getMediaPlayer().playMedia(file.getAbsolutePath()); 
    }
    //退出播放  
    public static void exit() {  
        frame.getMediaPlayer().release();  
        System.exit(0);  
    }  
	// 实现暂停按钮的方法
	public static void pause() {
		frame.getMediaPlayer().pause();
	}
	// 实现点击进度条跳转的方法
	public static void resume(){
		frame.getMediaPlayer().skip(-1000);
	}
	public static void skip(){
		frame.getMediaPlayer().skip(10000);
	}
	
	public static void jumpTo(float to) {
		frame.getMediaPlayer().setTime((long) (to * frame.getMediaPlayer().getLength()));
	}

	// 实现控制声音的方法
	public static void setVol(int v) {
		frame.getMediaPlayer().setVolume(v);
	}
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).