简体   繁体   中英

vlcj shows a black screen with an audio sound

Basically, i dunno where my error is, as i am trying to embedd a vlcj player USING java, but when i run this file, it only shows a black screen with an audio sound instead of a video.

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);

}

Your frame has no content, you never added anything to it.

You need to add your panel to the frame.

There are a number of ways to do this, in this case it's simplest to do:

frame.setContentPane(panel);

You should also look at using vlcj's EmbeddedMediaPlayerComponent, it's much easier (less lines of code) to set up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM