6

私はこのSOスレッドを読みましたが、いくつかの変更を加えてコードを使用しようとすると、黒いウィンドウが表示されます。ここで間違っていることを誰かに教えてもらえますか。メイン関数を持つクラスが1つだけあります。

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.sun.jna.NativeLibrary;

import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.player.embedded.videosurface.CanvasVideoSurface;
import uk.co.caprica.vlcj.runtime.windows.WindowsCanvas;

public class Canvas_Demo {

    // Create a media player factory
    private MediaPlayerFactory mediaPlayerFactory;

    // Create a new media player instance for the run-time platform
    private EmbeddedMediaPlayer mediaPlayer;

    private JPanel panel;
    private WindowsCanvas canvas;
    private JFrame frame;

    //Constructor
    public Canvas_Demo(String url){

        //Creating a panel that while contains the canvas
        panel = new JPanel();
        panel.setBackground(Color.BLACK);

        //Creating the canvas and adding it to the panel :
        canvas = new WindowsCanvas();
        panel.add(canvas);
        panel.revalidate();
        panel.repaint();

        //Creation a media player :
        mediaPlayerFactory = new MediaPlayerFactory();
        mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer();
        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);

        //Adding the panel to the 
        frame.add(panel);
        frame.setVisible(true);

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


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

        final String url = "C:/MyVideo.mp4";

        new Canvas_Demo(url);

    }

}

前もって感謝します。

4

3 に答える 3

4

ビデオのURL(Media Ressource LocatorとしてもMRLとも呼ばれます)を次のように変更するとC:\\MyVideo.mp4、ウィンドウにビデオが表示されます。

この議論は私を助けてくれました。

于 2013-01-16T11:23:00.880 に答える
1
//Creating the canvas and adding it to the panel :
canvas = new WindowsCanvas();
canvas.setSize(700, 500);
panel.add(canvas);
于 2012-12-25T13:41:36.610 に答える
1

私はこのようなことをしました

EmbeddedMediaPlayerComponent mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
        EmbeddedMediaPlayer embeddedMediaPlayer = mediaPlayerComponent.getMediaPlayer();

        Canvas videoSurface = new Canvas();
        videoSurface.setBackground(Color.black);
        videoSurface.setSize(800, 600);

        List<String> vlcArgs = new ArrayList<String>();

        vlcArgs.add("--no-plugins-cache");
        vlcArgs.add("--no-video-title-show");
        vlcArgs.add("--no-snapshot-preview");

        MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(vlcArgs.toArray(new String[vlcArgs.size()]));
        mediaPlayerFactory.setUserAgent("vlcj test player");
        embeddedMediaPlayer.setVideoSurface(mediaPlayerFactory.newVideoSurface(videoSurface));
        embeddedMediaPlayer.setPlaySubItems(true);

        final PlayerControlsPanel controlsPanel = new PlayerControlsPanel(embeddedMediaPlayer);
        PlayerVideoAdjustPanel videoAdjustPanel = new PlayerVideoAdjustPanel(embeddedMediaPlayer);

//            mediaPlayerComponent.getMediaPlayer().playMedia(Constant.PATH_ROOT + Constant.PATH_MEDIA + "tmp.mp4");
        JFrame mainFrame = new JFrame();
        mainFrame.setLayout(new BorderLayout());
        mainFrame.setBackground(Color.black);
        mainFrame.add(videoSurface, BorderLayout.CENTER);
        mainFrame.add(controlsPanel, BorderLayout.SOUTH);
        mainFrame.add(videoAdjustPanel, BorderLayout.EAST);

        //create a button which will hide the panel when clicked.
        mainFrame.pack();
        mainFrame.setVisible(true);

        embeddedMediaPlayer.playMedia("tmp.mp4");
于 2014-04-12T03:49:36.310 に答える