package asd;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
导入uk.co.caprica.vlcj.binding.LibVlc;
导入uk.co.caprica.vlcj.player.MediaPlayerFactory;
导入uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
导入uk.co.caprica.vlcj.runtime.RuntimeUtil;
导入java.net.URL;
导入javax.swing。*;
导入java.awt。*;
import java.net.MalformedURLException;
公共类VLCPlayer {
public static void main(final String [] args){
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),“ C:\ Program
Files \ VideoLAN \ VLC“);
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(),LibVlc.class);
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run(){
新的VLCPlayer(args);
}
});
}
私有VLCPlayer(String [] args){
JFileChooser fileChooser =新的JFileChooser();
fileChooser.showOpenDialog(null);
URL mediaUrl = null;
尝试{
mediaUrl = fileChooser.getSelectedFile()。toURI()。toURL();
}捕获(MalformedURLException ex){
.out.println(ex);
}
JFrame框架=新的JFrame(“Видеоойнатқыш”); MediaPlayerFactory mediaPlayerFactory =新的MediaPlayerFactory();
Canvas c = new Canvas();
c.setBackground(Color.black);
JPanel p =新的JPanel(); p.setLayout(new BorderLayout());
p.add(c,BorderLayout.CENTER);
frame.add(p,BorderLayout.CENTER);
EmbeddedMediaPlayer mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer();
mediaPlayer.setVideoSurface(mediaPlayerFactory.newVideoSurface(c));
frame.setLocation(100,100);
frame.setSize(1050,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
mediaPlayer.playMedia(“ D:\ film1.avi”);
}
}
答案 0 :(得分:0)
我还没有尝试过您的代码,但是我发现您已经将值硬编码在
mediaPlayer.playMedia("D:\film1.avi");
我想你想用
mediaPlayer.playMedia(mediaUrl);