在Java swing上使用vlcj
播放视频可以,但是不能暂停jbutton
和paused()
。
package tutorial;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent;
public class Tutorial {
public static void main(String[] args) {
JFrame frame = new JFrame("My First Media Player");
frame.setBounds(100, 100, 600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
EmbeddedMediaPlayerComponent mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
panel.add(mediaPlayerComponent, BorderLayout.CENTER);
frame.setContentPane(panel);
frame.setVisible(true);
mediaPlayerComponent.mediaPlayer().media().play("C:\\Users\\USER\\Desktop\\Rex Orange County.mp4");
}
}
最佳答案
// toggle pause
mediaPlayerComponent.mediaPlayer().controls().pause();
// explicitly set paused
mediaPlayerComponent.mediaPlayer().controls().setPause(true);
// play
mediaPlayerComponent.mediaPlayer().controls().play()