vlcj显示带有音频声音的黑屏

时间:2013-10-14 10:07:42

标签: java vlc libvlc vlcj

基本上,我不知道我的错误在哪里,因为我试图嵌入一个使用java的vlc播放器,但是当我运行这个文件时,它只显示一个带有音频声而不是视频的黑屏。

public class Play2 {

private MediaPlayerFactory mediaPlayerFactory;
// Create a new media player instance for the run-time platform
private EmbeddedMediaPlayer mediaPlayer;
private JFrame frame;
private String url;
private Canvas canvas;


public Play2(String url) {
this.url = url;

//Creation a media player :
mediaPlayerFactory = new MediaPlayerFactory();
mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer();
canvas = new Canvas();
JPanel panel=new JPanel();
panel.add(canvas, BorderLayout.CENTER);
mediaPlayer.setVideoSurface(mediaPlayerFactory.newVideoSurface(canvas));
//CanvasVideoSurface videoSurface = mediaPlayerFactory.newVideoSurface(canvas);
//mediaPlayer.setVideoSurface(videoSurface);

//Construction of the jframe :
frame = new JFrame("Demo with Canvas AWT");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(100, 100);
frame.setSize(700, 500);
frame.setVisible(true);

//Playing the video
mediaPlayer.playMedia(url);
}

public static void main(String[] args) {
NativeLibrary.addSearchPath("libvlc", "C:\\Program Files (x86)\\VideoLAN\\VLC");

final String url = "C:\\Users\\goldAnthony\\Videos\\Whistle.mp4";

new Canvas_Demo(url);

}

1 个答案:

答案 0 :(得分:0)

您的相框没有任何内容,您从未添加任何内容。

您需要将面板添加到框架中。

有很多方法可以做到这一点,在这种情况下最简单的方法是:

frame.setContentPane(panel);

您还应该考虑使用vlcj的EmbeddedMediaPlayerComponent,设置起来要容易得多(代码行数较少)。