2013-10-14 102 views
0

基本上,我不知道我的錯誤在哪裏,因爲我試圖嵌入vlcj播放器使用java,但是當我運行此文件時,它只顯示一個帶有音頻聲音的黑屏而不是視頻。vlcj顯示黑屏與音頻聲音

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

} 

回答

0

你的框架沒有內容,你從來沒有添加任何內容。

您需要將面板添加到框架。

有許多方法可以做到這一點,在這種情況下它是最簡單的事:

frame.setContentPane(panel); 

你也應該看看使用vlcj的EmbeddedMediaPlayerComponent,它更容易(較少的代碼行)成立。