如何使用vlcj在java中制作视频播放器? [英] How to make video player in java using vlcj?
本文介绍了如何使用vlcj在java中制作视频播放器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
public class VLCPlayer {
private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
//This is the path for libvlc.dll
public static void main(String[] args) {
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\Program Files\\VideoLAN\\VLC");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
SwingUtilities.invokeLater(() -> {
VLCPlayer vlcPlayer = new VLCPlayer();
});
}
private VLCPlayer() {
//MAXIMIZE TO SCREEN
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
JFrame frame = new JFrame();
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
frame.setContentPane(mediaPlayerComponent);
frame.setLocation(0, 0);
frame.setSize(300,400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
mediaPlayerComponent.getMediaPlayer().playMedia("D:\\centaur_1_xvid.avi");//Movie name which want to play
}
}
它现在运行良好,因为我使用的是 3.0.1 版本的 vlcj 和 jna 3.5.2 我想在视频播放器中添加速度(播放率)功能我该怎么做,我想知道视频暂停的时间以及播放时.
its running fine now as i'm using 3.0.1 version of vlcj and jna 3.5.2 i want to add speed(playbackrate) functionality in video player how can i do that and i want to know the timing when video paused and when played.
推荐答案
很简单.要获取时间或剩余时间,您可以使用 $T
表示时间,使用 $L
表示剩余时间.
在设置速度的情况下,您可以简单地使用api函数即
Very simple.
To get the time or time left, You can use $T
for time and $L
for time left.
And in case of setting speed, You can simply use the api function namely
/**
* Set the video play rate.
* <p>
* Some media protocols are not able to change the rate.
*
* @param rate rate, where 1.0 is normal speed, 0.5 is half speed, 2.0 is double speed and so on
* @return -1 on error, 0 on success
*/
int setRate(float rate);
如果您想了解更多信息,请查看文档 这里
If You want to know more, check the documentation here
更新
要获取时间,请使用此
UPDATE
To get the time , use this
/**
* Get the current play-back time.
*
* @return current time, expressed as a number of milliseconds
*/
long getTime();
检查上面的文档链接.
这篇关于如何使用vlcj在java中制作视频播放器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文