vlcj视频未显示,可以听到音频。 Java-Swing vlcj

时间:2019-06-18 19:57:42

标签: java swing video vlcj

我正在尝试在Java swing中播放视频。我只能听到音频,但视频没有显示。我正在使用EmbeddedMediaPlayerComponent。所有按钮也正确显示在屏幕上以及面板2中。

我尝试查看其他线程并更新了我的代码,但是没有用。有人可以帮忙吗?

更新:我正在使用macosx

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;

import uk.co.caprica.vlcj.binding.RuntimeUtil;
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent;

public class MediaPlayer extends JPanel {

// Declares our media player component
private EmbeddedMediaPlayerComponent mediaplayer;
// This string holds the media URL path
private static String mediapath;
private String mediaPath="";
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(), "/Applications/VLC.app/Contents/MacOS/lib");
    mediaplayer = new EmbeddedMediaPlayerComponent();

    panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(mediaplayer, BorderLayout.CENTER);


    //New code
    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);
    setLayout(new BorderLayout());
    add(panel, BorderLayout.CENTER);


}

public void play() {
        mediaplayer.mediaPlayer().media().play(mediaPath);
}

public static void main(String[] args) {


    mediapath = "/Users/name/Documents/Projects/Scenario2.mp4";
    MediaPlayer mediaplayer = new MediaPlayer(mediapath);
    JFrame ourframe = new JFrame("Sample");
    ourframe.setContentPane(mediaplayer);
    ourframe.setSize(840, 600);
    ourframe.setVisible(true);
    mediaplayer.play();
    ourframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

我希望在面板中看到该视频。

0 个答案:

没有答案