如何使用vlcj框架制作一个可以作为视频时间轴的Jslider
How to make a Jslider that can be a timeline for videos using vlcj framework
我在让我的 jslider 运行 与我播放的视频同步时遇到了一些麻烦。这是我的示例代码。
public Test() {
NativeLibrary.addSearchPath( RuntimeUtil.getLibVlcLibraryName(), "lib");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
mediaPlayer = new EmbeddedMediaPlayerComponent();
p2.setLayout(newBorderLayout());
p2.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
b2.setIcon(new ImageIcon("pause.png"));
b2.revalidate();
b3.setIcon(new ImageIcon("skip.png"));
b3.revalidate();
b3.repaint();
p2.add(mediaPlayer);
mediaPlayer.getMediaPlayer().playMedia("intranet.mp4");
slider.setValue((int) mediaPlayer.getMediaPlayer().getLength());
}
然后,在我的按钮上是我的示例代码..
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int time = (int) mediaPlayer.getMediaPlayer().getLength();
JOptionPane.showMessageDialog(null,time);
}
private void sliderStateChanged(javax.swing.event.ChangeEvent evt) {
label1.setText("Value" + slider.getValue());
}
private void b3ActionPerformed(java.awt.event.ActionEvent evt) {
mediaPlayer.getMediaPlayer().skip(10000);
JOptionPane.showMessageDialog(null, mediaPlayer.getMediaPlayer().getLength());
}
private void b2ActionPerformed(java.awt.event.ActionEvent evt) {
mediaPlayer.getMediaPlayer().pause();
b2.removeAll();
}
private void b1ActionPerformed(java.awt.event.ActionEvent evt) {
mediaPlayer.getMediaPlayer().skip(-10000);
int time = (int) mediaPlayer.getMediaPlayer().getLength();
JOptionPane.showMessageDialog(null, mediaPlayer.getMediaPlayer().getLength());
}
我的问题是我可以知道我播放的视频的总时间是多少,而我在播放视频时没有太多想法然后滑块也会 运行 指定时间。感谢提前的建议,期待中!!
使用重写的方法:Timechanged 并且link它到jslider,每次都会发送新的即时视频来改变滑块进度。
mediaplayer = new EmbeddedMediaPlayerComponent();
embededMediaPlayer = mediaplayer.getMediaPlayer();
embededMediaPlayer.setRepeat(true);
videoSurface = mediaplayer.getVideoSurface();
embededMediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
/**
*
* @param mediaPlayer play video
* @param newTime get every millisecond changed in the mediaplayer
* when is in playing mode
*/
@Override
public void timeChanged(MediaPlayer mediaPlayer, long newTime) {
super.timeChanged(mediaPlayer, newTime);
// here put you code to set new slider progress value
}
});
我在让我的 jslider 运行 与我播放的视频同步时遇到了一些麻烦。这是我的示例代码。
public Test() { NativeLibrary.addSearchPath( RuntimeUtil.getLibVlcLibraryName(), "lib"); Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class); mediaPlayer = new EmbeddedMediaPlayerComponent(); p2.setLayout(newBorderLayout()); p2.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); b2.setIcon(new ImageIcon("pause.png")); b2.revalidate(); b3.setIcon(new ImageIcon("skip.png")); b3.revalidate(); b3.repaint(); p2.add(mediaPlayer); mediaPlayer.getMediaPlayer().playMedia("intranet.mp4"); slider.setValue((int) mediaPlayer.getMediaPlayer().getLength()); }
然后,在我的按钮上是我的示例代码..
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int time = (int) mediaPlayer.getMediaPlayer().getLength();
JOptionPane.showMessageDialog(null,time);
}
private void sliderStateChanged(javax.swing.event.ChangeEvent evt) {
label1.setText("Value" + slider.getValue());
}
private void b3ActionPerformed(java.awt.event.ActionEvent evt) {
mediaPlayer.getMediaPlayer().skip(10000);
JOptionPane.showMessageDialog(null, mediaPlayer.getMediaPlayer().getLength());
}
private void b2ActionPerformed(java.awt.event.ActionEvent evt) {
mediaPlayer.getMediaPlayer().pause();
b2.removeAll();
}
private void b1ActionPerformed(java.awt.event.ActionEvent evt) {
mediaPlayer.getMediaPlayer().skip(-10000);
int time = (int) mediaPlayer.getMediaPlayer().getLength();
JOptionPane.showMessageDialog(null, mediaPlayer.getMediaPlayer().getLength());
}
我的问题是我可以知道我播放的视频的总时间是多少,而我在播放视频时没有太多想法然后滑块也会 运行 指定时间。感谢提前的建议,期待中!!
使用重写的方法:Timechanged 并且link它到jslider,每次都会发送新的即时视频来改变滑块进度。
mediaplayer = new EmbeddedMediaPlayerComponent();
embededMediaPlayer = mediaplayer.getMediaPlayer();
embededMediaPlayer.setRepeat(true);
videoSurface = mediaplayer.getVideoSurface();
embededMediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
/**
*
* @param mediaPlayer play video
* @param newTime get every millisecond changed in the mediaplayer
* when is in playing mode
*/
@Override
public void timeChanged(MediaPlayer mediaPlayer, long newTime) {
super.timeChanged(mediaPlayer, newTime);
// here put you code to set new slider progress value
}
});