2012-07-11 155 views
2

請看看下面的代碼VLCJ不能播放視頻

import com.sun.jna.Native; 
import uk.co.caprica.vlcj.binding.LibVlc; 
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent; 
import uk.co.caprica.vlcj.runtime.RuntimeUtil; 

import com.sun.jna.NativeLibrary; 
import javax.swing.JFrame; 
import javax.swing.SwingUtilities; 

public class Tutorial2B { 

    private final EmbeddedMediaPlayerComponent mediaPlayerComponent; 

    public static void main(String[] args) { 
    SwingUtilities.invokeLater(new Runnable() { 
     @Override 
     public void run() { 
     new Tutorial2B(); 
     } 
    }); 
    } 

    private Tutorial2B() { 

     NativeLibrary.addSearchPath(
     RuntimeUtil.getLibVlcLibraryName(), "c:/program files/videolan/vlc" 
    ); 
    Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class); 

    JFrame frame = new JFrame("vlcj Tutorial"); 

    mediaPlayerComponent = new EmbeddedMediaPlayerComponent(); 

    frame.setContentPane(mediaPlayerComponent); 

    frame.setLocation(100, 100); 
    frame.setSize(1050, 600); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    frame.setVisible(true); 

    System.out.println("Running"); 

    mediaPlayerComponent.getMediaPlayer().playMedia("I:/YouTube (1).mp4"); 
    } 
} 

此代碼應該發揮使用VLCJ媒體。但事實並非如此,它只是用一個空白的窗口打開框架,沒有視頻,沒有聲音。有什麼問題?請幫助

+0

有人請幫忙! – 2012-07-11 18:42:53

+0

運行上述代碼時,是否有任何報告的VLC異常,如'java.lang.UnsatisfiedLinkError'?如果是,請嘗試將''c:/ program files/videolan/vlc「'更改爲'」c:\\ program files \\ videolan \\ vlc「'和I:/ YouTube(1).mp4」 ''to'「I:\\ YouTube(1).mp4」' – 2012-07-12 08:49:54

+0

除此之外,請嘗試使用正確版本的VLCJ庫和正確版本的libVLC庫。請參閱http://code.google.com/p/vlcj/wiki/WhichVersion – 2012-07-12 08:52:20

回答