2013-02-04 47 views
1

我目前正在開發可以播放mkv格式的java媒體播放器。我正在使用VLCJ,除了當我嘗試更改不工作的音軌時,一切正常。Java VLCJ播放器,設置音軌不起作用

這裏是代碼

公共類媒體播放器{

private static JFileChooser filechooser = new JFileChooser(); 

public mediaplayer() { 
} 

public static void main(String[] args) { 
    String vlcPath = "", mediaPath = ""; 
    File ourfile; 

    filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY); 
    filechooser.showSaveDialog(null); 
    ourfile = filechooser.getSelectedFile(); 
    mediaPath = ourfile.getAbsolutePath(); 


    EmbeddedMediaPlayerComponent mediacom = new EmbeddedMediaPlayerComponent(); 



     JFrame frame = new JFrame(); 
     frame.setContentPane(mediacom); 
     frame.add(canvas); 
     frame.setLocation(100, 100); 
     frame.setSize(1050, 600); 
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

     frame.setVisible(true); 

    MediaPlayer mplayer = mediacom.getMediaPlayer(); 

    mplayer.playMedia(mediaPath); 
    mplayer.setAudioTrack(1); 







} 

}

回答

1

在libVLC版本VLC 2.0.5原生API調用設置音軌被竊聽了。

利用libVLC 2.0.5中的修復,設置音軌可以可靠地工作,但是您不能僅假設從0..N的簡單索引,並且您不能假定連續的音軌編號 - 您必須通過調用來枚舉音軌mediaPlayer.getAudioDescriptions()。返回的TrackDescription對象包含應與mediaPlayer.setAudioTrack()一起使用的音軌標識符。

要禁用音頻,您可以選擇音軌的音軌標識符,其描述爲「禁用」。

另請注意,您可能無法在調用mediaPlayer.playMedia()後立即設置音軌。媒體異步啓動,您可能需要等到媒體實際啓動和/或已被解析,然後才能使用軌道信息。