简体   繁体   English

vlcj视频未显示,但听到了视频声音

[英]vlcj video not showing, but video sound is heard

when the application is run, the sound is heard and other button controls are visible on the frame, but the panel containing the video does not show any black screen neither is it displayed on the frame. 运行该应用程序时,在框架上可以听到声音并且可以看到其他按钮控件,但是包含视频的面板没有显示任何黑屏,也没有在框架上显示。

public class MediaPlayer extends JPanel {

private JFrame ourframe = new JFrame();
//Declares our media player component
private EmbeddedMediaPlayerComponent mediaplayer;
//This string holds the media URL path
private String mediapath = "";
//This string holds the vlc URL path
private final String vlcpath = "C:\\Program Files (x86)\\VideoLAN\\VLC";
private JPanel panel, panel2;
private JButton play_btn, stop_btn, foward_btn, rewind_btn, enlarge_btn;
private JSlider timeline;

public MediaPlayer(String mediapath) {
    this.mediapath = mediapath;
    NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcpath);
    mediaplayer = new EmbeddedMediaPlayerComponent();

    panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(mediaplayer, BorderLayout.CENTER); //panel containing the video

    play_btn = new JButton("play");
    stop_btn = new JButton("stop");
    foward_btn = new JButton("ff");
    rewind_btn = new JButton("rew");
    enlarge_btn = new JButton("enlarge");

    timeline = new JSlider(0, 100, 0);
    timeline.setMajorTickSpacing(10);
    timeline.setMajorTickSpacing(5);
    timeline.setPaintTicks(true);

    panel2 = new JPanel();
    panel2.setLayout(new FlowLayout(FlowLayout.CENTER));
    panel2.add(play_btn);
    panel2.add(stop_btn);
    panel2.add(foward_btn);
    panel2.add(rewind_btn);
    panel2.add(enlarge_btn);
    panel2.add(timeline);
    panel.add(panel2, BorderLayout.SOUTH);
    add(panel);
}

public void play() {
    mediaplayer.getMediaPlayer().playMedia(mediapath);
}

public static void main(String[] args) {
    //Declare and initialize local variables
    String mediaPath = "";
    mediaPath = "C:\\Users\\goldAnthony\\Desktop\\Videos\\Whistle.mp4";

    //creates instances of the VlcPlayer object, pass the mediaPath and invokes the method "run"
    MediaPlayer mediaplayer = new MediaPlayer(mediaPath);
    JFrame ourframe = new JFrame();
    ourframe.setContentPane(mediaplayer);
    ourframe.setSize(720, 560);
    ourframe.setVisible(true);
    mediaplayer.play();
    ourframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

} }

This is because you are adding the video surface to a JPanel without choosing an appropriate layout manager. 这是因为您要在不选择适当的布局管理器的情况下将视频界面添加到JPanel。

By default JPanel has a FlowLayout and this will layout components according to their preferred size. 默认情况下,JPanel具有FlowLayout,这将根据组件的首选大小对其进行布局。

The video surface panel has no preferred size set. 视频面板没有设置首选的尺寸。

The solution is to set a layout manager like BorderLayout on the main panel. 解决方案是在主面板上设置一个类似于BorderLayout的布局管理器。

So at the end of your constructor, instead of this... 因此,在构造函数的末尾,而不是此...

add(panel);

...do this... ...做这个...

setLayout(new BorderLayout());
add(panel, BorderLayout.CENTER);

Cross-posted at [1]. 交叉发布于[1]。

[1] https://groups.google.com/forum/#!topic/vlcj-users/m0zG-fx4qm8 [1] https://groups.google.com/forum/#!topic/vlcj-users/m0zG-fx4qm8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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