标签:height frame 自制 core 入门 OLE 版本 vax rip
利用VLC自制一个java视频播放器
Java 虚拟机的CPU体系结构和本机LibVLC库 - 如果使用32位JVM,则必须使用32位版本的VLC;如果使用64位JVM,则必须使用64位版本的VLC。你不能混合CPU架构,它不会工作。对于所有平台,至少需要Java 1.6版本。对于Linux和Windows平台,也完全支持Java 1.7和1.8版本。java -version, 没写是64位的就是32位的.
vlc-2.2.4-win32.zip.new NativeDiscovery().discover() (后面会讲) 创建播放器(即必须安装正确版本的exe文件),而不能用设置库路径的方式创建(至少我的电脑不行.)MediaPlayerForJava,在根目录下创建连个文件夹 lib,vlc. lib文件夹用来放vlcj下的jar包,vlc文件夹用来放vlc播放器的组件。
lib文件夹下,并构建路径(选中 lib下的四个jar包,右击 - BuildPath-AddToBuildPath)
libvlc.dll,文件libvlccore.dll,文件夹piugins,到项目中的vlc文件夹。如果是exe版的,找到安装目录,同样找到这两个文件和一个文件夹复制粘贴到vlc中。
com.feihuang.main,创建一个类Main,创建一个包com.feihuang.view,创建一个类View.写以下代码,运行一下。Main.java
package com.feihuang.main;
import javax.swing.SwingUtilities;
import com.feihuang.view.View;
public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
View frame = new View();
frame.setTitle("MediaPlayer");
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
View.java
package com.feihuang.view;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
public class View extends JFrame {
private JPanel contentPane;
public View() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
}
}

libvlc.dll,文件libvlccore.dll,文件夹piugins;一共有两种方法实现找到播放器组件。boolean found = new NativeDiscovery().discover();如果查找成功返回true,否则返回false。此方法想要成功,必须安装vlc,即使用的是exe版vlc。 NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),
"vlc");
即之前我们将播放器组件放在了vlc文件夹下,让程序到vlc文件夹下去找
View.java的构造方法中创建播放器组件的对象并添加到容器中去。并创建公共方法,获得播放器。 //创建一个容器放播放器组件对象
JPanel player = new JPanel();
contentPane.add(player, BorderLayout.CENTER);
player.setLayout(new BorderLayout(0, 0));
//创建播放器组件并添加到容器中去
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
player.add(mediaPlayerComponent);
public EmbeddedMediaPlayer getMediaPlayer(){
return mediaPlayerComponent.getMediaPlayer();
}
Main.java中的程序入口main方法添加文件路径frame.getMediaPlayer().playMedia("c:\\\mysourse\\\1.mp4");Main.java
package com.feihuang.main;
import javax.swing.SwingUtilities;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import com.feihuang.view.View;
import com.sun.jna.NativeLibrary;
public class Main {
private static View frame;
public static void main(String[] args) {
//new NativeDiscovery().discover();
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),
"vlc");
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
frame = new View();
frame.setTitle("MediaPlayer");
frame.setVisible(true);
frame.getMediaPlayer().playMedia("c:\\mysourse\\1.mp4");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
View.java
package com.feihuang.view;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
public class View extends JFrame {
private JPanel contentPane;
private EmbeddedMediaPlayerComponent mediaPlayerComponent;
public View() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));
JPanel player = new JPanel();
contentPane.add(player, BorderLayout.CENTER);
player.setLayout(new BorderLayout(0, 0));
//创建播放器组件并添加到容器中去
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
player.add(mediaPlayerComponent);
}
public EmbeddedMediaPlayer getMediaPlayer(){
return mediaPlayerComponent.getMediaPlayer();
}
}



问题就解决了~
标签:height frame 自制 core 入门 OLE 版本 vax rip
原文地址:https://www.cnblogs.com/code-fly-blogs/p/9902308.html